【发布时间】:2023-04-02 04:02:01
【问题描述】:
我正在尝试做的是这样的事情。
图片一
无论是哪个设备。它应该在屏幕上只显示四行,以后用户可以滚动查看其他行
我正在使用垂直线性布局权重来实现这一点,但它并没有按照我试图实现这一点的方式发生。当我添加更多行时,它会给我这样的屏幕
图片二
下面是我的布局 xml,它将屏幕作为图像之一,但添加更多行会提供图像两个视图
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightGray"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="1dp"
android:weightSum="4"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
android:id="@+id/abulation"
style="@style/icon"
android:background="@drawable/wudu_96" />
<ImageButton
android:id="@+id/masjid"
style="@style/icon"
android:background="@drawable/masjid_96" />
<ImageView
android:id="@+id/restroom"
style="@style/icon"
android:background="@drawable/restroom_96" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
android:id="@+id/dressing"
style="@style/icon"
android:background="@drawable/dressing_96" />
<ImageButton
style="@style/icon"
android:background="@drawable/icon_selector"
android:scaleType="fitXY" />
<ImageButton
android:id="@+id/Favourite"
style="@style/icon"
android:background="@drawable/favourite_96"
android:onClick="random"
android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="@style/icon"
android:background="@drawable/fear_96" />
<ImageView
style="@style/icon"
android:background="@drawable/fear_96" />
<ImageView
style="@style/icon"
android:background="@drawable/fear_96" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="@style/icon"
android:background="@drawable/fear_96" />
<ImageView
style="@style/icon"
android:background="@drawable/fear_96" />
<ImageView
style="@style/icon"
android:background="@drawable/fear_96" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
我知道我在做错事来实现这一目标。请帮助我如何获得我想要的视图。
【问题讨论】:
-
为什么不使用带有网格的回收站视图。?我认为这是实现这一目标的更好方法
-
试试这个方法——在第一个线性布局中(android:weightSum="1.0")和里面的那些(android:layout_width="0dp" android:layout_weight="0.25")——见如果这给了你 4 个相等的行
-
这些类别是静态的吗?
-
IMO,这不是
layout_weight的问题,您需要找到可用的屏幕高度,将其除以 4,然后在运行时将该高度应用于每个LinearLayout。跨度> -
垂直所以试试 (android:layout_height="0dp")
标签: android android-linearlayout android-scrollview