【发布时间】:2015-03-27 12:40:01
【问题描述】:
当将 RelativeLayout 放入 ScrollView 时,我在将片段附加到 RelativeLayout 时遇到问题。亲爱的请看xml代码——
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:obs="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:textColor="#9982d6"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:textColor="#9982d6"
android:textSize="20sp"/>
</RelativeLayout>
<View
android:id="@+id/topDivider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#9982d6"
/>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#848484"
android:textSize="14sp" />
<View
android:layout_width="match_parent"
android:layout_height="3.5dp"
android:layout_alignParentBottom="true"
android:background="#4ccdd9"
android:visibility="gone" />
<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp" />
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="0dp" />
</LinearLayout>
</ScrollView>
在上面的 xml 代码中,我必须在 RelativeLayout GraphContainer 中附加一个片段,该片段不起作用。如果我不使用 ScrollView,则附加片段有效。请帮忙...
【问题讨论】:
-
将线性布局高度改为fill_parent
-
为什么要将第一个RelativeLayout高度提供给match_parent,在垂直方向的线性布局内。
-
滚动视图高度应始终为 wrap_content 否则意义较小
-
建议使用布局权重
-
更改 ScrollView、LinearLayout 和 RelativeLayout 的高度都不起作用。
标签: android android-layout android-fragments android-relativelayout xml-layout