How to avoid overlap view in relative layout in android?

前端 未结 8 1706
Happy的楠姐
Happy的楠姐 2020-12-23 13:43


        
相关标签:
8条回答
  • 2020-12-23 14:12

    I had a similar problem and tried pretty much everything suggested here and in other similar threads.

    The one additional thing that did it for me was to add:

    android:layout_toStartOf="@+id/youroverlappeditem"
    

    so the overlapping item will only run up to the overlapped item.

    layout_toLeftOf was not enough on its own

    and of course ellipsize="end" was needed as appropriate.

    Mine was for a recyclerview with a relative layout.

    0 讨论(0)
  • 2020-12-23 14:15

    Use layout_toStartOf in the first item with second item +id under double quotes

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    
        <TextView
            android:id="@+id/email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_toStartOf="@+id/selectaccount"
            android:text="very long text which used to overlap over radio button"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
        <RadioButton
            android:id="@+id/selectaccount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true" />
    
    </RelativeLayout>
    

    note this argument in textview

    android:layout_toStartOf="@+id/selectaccount"
    

    An XML is read from top to bottom

    so this is how the Layout is rendered in Android

    • android:layout_toStartOf="@id/item means that item is defined above this line
    • android:layout_toStartOf="@+id/item means that item will appear later somewhere below this line
    0 讨论(0)
  • 2020-12-23 14:18

    If you are using this kind of design than you should use linear Layout. and use Table Rows in it to display this kind of view.

    and also use weight so that your view doesn't et overlap on other views. try like this:

    <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" >
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    <TableRow 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:weightSum="10">
        <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"
            android:text="test"
            android:layout_weight="5" />
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/textView1"
            android:textSize="20sp" 
            android:text="test"
            android:layout_weight="5"/>
    </TableRow>
    
    </LinearLayout>
    </ScrollView>
    

    Hope it Helps!!

    0 讨论(0)
  • 2020-12-23 14:18

    Add this line one your xml layout

    tools:ignore="RelativeOverlap"

    0 讨论(0)
  • 2020-12-23 14:23

    Align the all the textviews to leftOf imageview like lastone : android:layout_toLeftOf="@id/imageView1"

    0 讨论(0)
  • 2020-12-23 14:23

    Try constraint layout. It simplifies your layout.

    0 讨论(0)
提交回复
热议问题