java - Android Java片段半屏显示
问题描述
我正在开发 android 应用程序。在fragment_auction_products.xml 中的recycler-view 中显示卡片列表时出现问题。当我导航到 FragmentAuctionProducts 时,我遇到 了问题
如您所见,我的列表在 50% 空间为空后开始显示......我该如何解决这个问题?
我的 fragment_auction_products.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_auction_products_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="@+id/home_auction_products_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/spinner_ring"
android:indeterminateOnly="true" />
</LinearLayout>
我的回收站查看项目:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:gravity="center"
android:background="@drawable/layer_shadow"
android:orientation="horizontal">
<ImageView
android:id="@+id/home_auction_products_recycler_view_image"
android:layout_margin="4dp"
android:layout_width="125dp"
android:layout_height="150dp"
android:src="@drawable/card_example_1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:orientation="vertical"
android:paddingTop="15dp">
<TextView
android:id="@+id/home_auction_products_recycler_view_title"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/muli_bold"
android:text="Title"
android:textColor="@color/colorBlack"
android:textSize="14dp" />
<TextView
android:id="@+id/home_auction_products_recycler_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/muli_bold"
android:text="id"
android:textColor="@color/colorBlack"
android:textSize="0dp" />
<TextView
android:id="@+id/home_auction_products_recycler_view_current_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/muli_bold"
android:text="50000 тг"
android:textColor="@color/colorTextYellow"
android:textSize="16dp" />
<TextView
android:id="@+id/home_auction_products_recycler_view_start_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/muli"
android:text="start-price"
android:textColor="@color/colorBlack"
android:textSize="12dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:background="@drawable/auction_products_shape"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="2dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">
<TextView
android:id="@+id/home_auction_products_recycler_view_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/muli"
android:gravity="center"
android:text="10"
android:textColor="@color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/muli"
android:gravity="center"
android:text="ДНЕЙ"
android:textColor="@color/colorWhite"
android:textSize="6dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/auction_products_shape"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="2dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">
<TextView
android:id="@+id/home_auction_products_recycler_view_hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/muli"
android:gravity="center"
android:text="12"
android:textColor="@color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/muli"
android:gravity="center"
android:text="ЧАСОВ"
android:textColor="@color/colorWhite"
android:textSize="6dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">
<TextView
android:id="@+id/home_auction_products_recycler_view_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_mdi_keyboard_arrow_right"
android:fontFamily="@font/muli"
android:textColor="@color/colorTextGray"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
我称之为片段的主要容器:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
tools:context=".activity.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/bottom_nav_bar">
<FrameLayout
android:id="@+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:windowBackground"
app:menu="@menu/menu" />
</RelativeLayout>
解决方案
只需使用android:layout_alignParentTop
.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_auction_products_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="@+id/home_auction_products_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/spinner_ring"
android:indeterminateOnly="true" />
</LinearLayout>
希望这可以帮助。
推荐阅读
- java - 带有标签和按钮的 Vaadin 8 水平布局
- python-3.x - 使用 Python 以 sudo 启动 shell 脚本时如何验证正确的密码
- jquery - 为什么在下拉列表中追加数据后,表单提交为控制器中的下拉列表发送空值
- azure - Terraform 授予带有 msi 访问权限的 azure 函数应用程序以访问 azure keyvault
- mysql - SQL:计算两个值之间出现的次数
- javascript - 如何从嵌套的 Promise 函数返回 Promise 对象
- angular - Angular CanDeactivate 不起作用
- javascript - 关于如何构建node js服务程序的问题
- java - 没有父 pom 的版本的插件管理
- numpy - 将有符号浮点数转换为 uint8 图像 opencv