Aligning ImageView to right of the layout android

前端 未结 8 1164
生来不讨喜
生来不讨喜 2021-02-04 01:26

I have an layout




        
相关标签:
8条回答
  • 2021-02-04 01:29
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF">
    
        <TextView android:id="@+id/groupname"
             android:paddingLeft="50dp"
             android:textSize="16dp"
             android:textColor="#000000"
             android:textStyle="normal"
             android:layout_width="fill_parent"
             android:layout_height="50dp"
             android:layout_weight="0.9"
             android:background="@color/black"/>
         <ImageView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="right"
                 android:background="#ffffff" 
                 android:src="@drawable/checkin"
                 android:layout_weight="0.1"/>
    
    </LinearLayout>
    

    Try this, hope this will help.

    Prview1 enter image description here

    0 讨论(0)
  • 2021-02-04 01:30
    <?xml version="1.0" encoding="utf-8"?>
    

    <TextView android:id="@+id/groupname"
         android:paddingLeft="50px"
         android:textSize="16px"
         android:background="#FFFFFF"
         android:textColor="#000000"
         android:textStyle="normal"
         android:layout_width="wrap_content"
         android:layout_height="50px"/>
     <ImageView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_gravity="right"
             android:layout_marginRight="6dp"
             android:background="#ffffff"
             android:layout_alignParentRight="true" 
             android:src="@drawable/sort"/>
    

    0 讨论(0)
  • 2021-02-04 01:35

    use android:layout_weight="1" for text view

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#FFFFFF">
    
      <TextView android:id="@+id/groupname"
         android:paddingLeft="50px"
         android:textSize="16px"
         android:layout_weight="1"
         android:background="#FFFFFF"
         android:textColor="#000000"
         android:textStyle="normal"
         android:layout_width="0dp"
         android:layout_height="50px"/>
     <ImageView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="right"
             android:layout_marginRight="6dp"
             android:background="#ffffff" 
             android:src="@drawable/sort"/>
    
    </LinearLayout>
    
    0 讨论(0)
  • 2021-02-04 01:36

    Either use RelativeLayout and set property of TextView as follows:

    layout_width=fill_parent
    layout_height=wrap_content
    left_of="@+id/imgView"
    

    and to ImageView

    layout_width=wrap_content
    layout_height=wrap_content
    alignparentright=true
    
    0 讨论(0)
  • 2021-02-04 01:41

    you should add such thing in xml... to the object you want align right...

    android:layout_alignParentRight="true" 
    android:layout_marginRight="..dp"
    
    0 讨论(0)
  • 2021-02-04 01:50

    Try with RelativeLayout.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF">
    
        <TextView
            android:id="@+id/groupname"
            android:layout_width="wrap_content"
            android:layout_height="50px"
            android:background="#FFFFFF"
            android:paddingLeft="50px"
            android:textColor="#000000"
            android:textSize="16px"
            android:textStyle="normal" />
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="#ffffff"
            android:src="@drawable/ic_launcher" />
    
    </RelativeLayout>
    
    0 讨论(0)
提交回复
热议问题