我有以下布局,由于某种原因,ScrollView重叠了视图。 我不太了解android中weight和layout_weight属性的全部用法。 我认为这与我的问题有关。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>
<ImageView
android:id="@+id/secondbar"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/topbarr"
android:scaleType="fitXY"
/>
<ScrollView
android:id="@+id/buttonlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_below="@+id/secondbar"
android:scrollbarFadeDuration="0"
>
</ScrollView>
</RelativeLayout>
答案 0 :(得分:1)
首先,如果您希望自己的观看次数低于另一个,那么您应该只有一个android:layout_alignParentTop="true"
的观看次数。
其次,您只需为每个变量使用@+id
一次。声明后,您可以@id
引用它。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>
<ImageView
android:id="@+id/secondbar"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/topbar"
android:scaleType="fitXY"
/>
<ScrollView
android:id="@+id/buttonlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@id/secondbar"
android:scrollbarFadeDuration="0"
>
</ScrollView>
</RelativeLayout>
答案 1 :(得分:1)
android weight和layout_weight属性只能用于Linearlayout或其childLayout。 至于layout_weight与LinearLayout的子视图一起使用,LinearLayout以子比例划分子宽度或高度。 如果你给layout_weight你应该将相应的宽度或高度设置为0dp。 layout_weightSum与Parentlayout的父级一起使用,以定义它可以划分的比例。 这对你的问题现在没有任何作用,因为你正在使用RelativeLayout所有的childViews从topleft角开始。你必须在relativeLayout中给出约束来对齐你的观点
对于scrollview 经常使用的子项是垂直方向的LinearLayout,呈现用户可以滚动的顶级项目的垂直数组。
你永远不应该使用带有ListView的ScrollView,因为ListView负责自己的垂直滚动。
答案 2 :(得分:0)
采用线性布局并根据所需的UI外观调整重量 在这里,它将为2个imageview和scrollview划分三个相等的一半
<ImageView
android:id="@+id/topbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher"
/>
<ImageView
android:id="@+id/secondbar"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:layout_below="@+id/topbarr"
android:scaleType="fitXY"
/>
<ScrollView
android:id="@+id/buttonlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_below="@+id/secondbar"
android:scrollbarFadeDuration="0"
>
</ScrollView>