Android : Align image on top right hand corner of button

后端 未结 2 1318
无人及你
无人及你 2020-12-16 04:33

I have an image which looks like a checkbox, that i would like to align on top right hand corner of button. Have tried relative layout but could not achieve desired result.

相关标签:
2条回答
  • 2020-12-16 04:52

    It look like this :

    enter image description here

    Just play with the android:paddingTop="-10dp" as you like.

    Here the code :

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/widget_icon"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <Button
                android:id="@+id/filter"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="7dp"
                android:background="#0000FF"
                android:gravity="center"
                android:paddingBottom="25dp"
                android:paddingTop="25dp"
                android:text="Sort"
                android:textColor="#FFFFFF" />
    
            <ImageView
                android:id="@+id/widget_title_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="top|right"
                android:adjustViewBounds="true"
                android:paddingTop="-10dp"
                android:scaleType="fitStart"
                android:src="@drawable/checkbtn" />
    
        </FrameLayout>
    
    0 讨论(0)
  • 2020-12-16 05:11

    Check this one, hopefully it will help you. Here is the image

    <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main_widget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dip"
        android:focusable="true" >
    
        <ImageView
            android:id="@+id/icon"
            android:layout_width="60dip"
            android:layout_height="60dip"
            android:layout_marginTop="8dp"
            android:background="@drawable/ic_launcher"
            android:scaleType="center" />
    
    
        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="-10dip"
            android:layout_toRightOf="@+id/icon"
            android:gravity="center"
            android:text="" />
    
        </RelativeLayout>
    

    EDIT If you want to move checkbox little further to imageview then increase the android:layout_marginLeft="-10dip" to android:layout_marginLeft="-20dip". Just play with it. :)

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