【问题标题】:How to align ImageButton to right in horizontal LinearLayout如何在水平 LinearLayout 中将 ImageButton 向右对齐
【发布时间】:2015-07-02 10:52:22
【问题描述】:

我在LinearLayout 中有一个ImageButton。我尝试将ImageButton 放在水平LinearLayout 的右侧。我使用layout_gravity="right",但它不起作用。请帮帮我。

 <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>

【问题讨论】:

标签: android android-layout


【解决方案1】:

将按钮的重力设置为向右,如下所示: android:layout_gravity="right"

【讨论】:

    【解决方案2】:

    ImageButton 的父布局上使用 android:gravity="right"。您也可以从中删除android:layout_gravity="right"

    【讨论】:

      猜你喜欢
      • 2014-01-10
      • 2012-09-12
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 2013-03-12
      相关资源
      最近更新 更多