How to avoid overlap view in relative layout in an

2019-01-31 06:19发布

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView1"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView2"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView3"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView4"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView5"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView6"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView7"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView8"
        android:textSize="20sp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView9" />

    <TextView
        android:id="@+id/textView10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="商店圖片:"
        android:textSize="15sp"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@id/imageView1" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/textView10"
        android:contentDescription="@string/top" />
</RelativeLayout>

Simple output:
textview1     textview9
textview2     imageview1
.
.
.
button1

The above layout is a page that divide horizitonally, for the left side , there is a list of textview and button , for the right side, there is an image view. The problem is: when the textview content is too long, the imageview will overlap the content of it, besides using bringtofront(), are there any way (in xml ) to resize the width of the text view if it overlap with image view?

8条回答
相关推荐>>
2楼-- · 2019-01-31 06:49

Try constraint layout. It simplifies your layout.

查看更多
\"骚年 ilove
3楼-- · 2019-01-31 07:00

You can overcome that issue by clicking on "infer constraints". Follow the picture which will show the way:

HowTo AndroidStudio

查看更多
登录 后发表回答