在RelativeLayout中重叠

时间:2015-05-15 16:05:21

标签: android android-layout android-linearlayout android-relativelayout

我有一个RelativeLayout,其中包含2个linearlayouts,其中一个应始终与bottom对齐(用于注销目的。),另一个从top开始,包含2个viewstubs。这两个视图库具有不同的高度,其中只有一个同时可见。

我的问题是如果我做top toplayout对齐top和bottom linearlayout对齐底部,如果viewstubs height更大,内容重叠。

我无法将它们设置在任何上方和下方,就好像视图存储高度较小的视图不是从角落开始的。

如何避免重叠?

2 个答案:

答案 0 :(得分:0)

使用3个LinearLayouts设置中心布局,就像您在上方/下方所做的那样 并将该居中布局添加到滚动视图中 在它仍然你的问题没有解决所以只是让我知道:)快乐的编码。

答案 1 :(得分:0)

你不会对两个子视图的位置说些什么。所以,我的意思是每个视图都有= 1/2屏幕。试试我的解决方案。

abc.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="10">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:orientation="horizontal"
        android:weightSum="2"
        android:background="#116611">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#116611"
            android:layout_weight="1">
            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <LinearLayout
                    android:id="@+id/ll_insideScroll1"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                </LinearLayout>
            </ScrollView>
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#118811"
            android:layout_weight="1">
            <ScrollView
                android:id="@+id/scrollView2"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </ScrollView>
        </LinearLayout>
    </LinearLayout>
    <!--Bottom LinearLayout-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#113311"
        android:layout_weight="2">

    </LinearLayout>

</LinearLayout>

并测试此布局:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.abc);
        LinearLayout ll_insideScroll1 = (LinearLayout)findViewById(R.id.ll_insideScroll1);
        for(int i = 0; i < 50;i++){
            TextView v = new TextView(this);
            v.setText("TextView "+i);
            ll_insideScroll1.addView(v,i);
        }
    }
相关问题