Overlapping in RelativeLayout

安稳与你 提交于 2019-12-25 04:49:15

问题


I have one RelativeLayout which contains 2 linearlayouts, one should always be aligned with bottom (for log out purpose.) and the other starts from top and contains 2 viewstubs. These two viewstubs have different heights any only one of them will be visible at same time.

My problem is if I make top linearlayout align top and bottom linearlayout align bottom, contents overlap if viewstubs height is bigger.

I can not make them above and below of any as if the viewstubs height is smaller views start not from the corners.

How can I avoid them from overlapping?


回答1:


Use 3 LinearLayouts set the center layout as it is which you have done above/below and add that centered layout into scroll view after it still your problem do not solve so just let me know :) Happy coding.




回答2:


you don't say anything about position of two subviews. So, I mean each view has with = 1/2 screen. Just try my solution.

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>

and for test this layout:

    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);
        }
    }


来源:https://stackoverflow.com/questions/30264007/overlapping-in-relativelayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!