简体   繁体   中英

How to align ImageButton to right in horizontal LinearLayout

I have a ImageButton in LinearLayout . I try to put a ImageButton to right in horizontal LinearLayout . I use layout_gravity="right" but it doesn't work. Please help me.

 <LinearLayout
    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"
    android:weightSum="5"
    tools:context="com.startsoft.musicalsound.MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3"
        android:background="@drawable/img_bg_header"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btn_menu"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="right"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_action_sort_by_size" />
    </LinearLayout>

Use android:gravity="right" on the parent layout of your ImageButton . You can also remove android:layout_gravity="right" from it.

像这样将按钮的重力设置为右:android:layout_gravity =“right”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM