如何在线性布局中右对齐

时间:2013-12-26 23:44:08

标签: android layout user-interface alignment nine-patch

我将此布局作为列表项:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:gravity="center_vertical"
              android:layout_width="match_parent"
              android:orientation="horizontal"
              android:minHeight="42.3dp"
              android:layout_height="wrap_content">

    <TextView android:id="@+id/txtTagName"
              android:textColor="@color/White"
              android:layout_width="wrap_content"
              android:layout_height="32dp"
              android:layout_marginLeft="10dp"
              android:textSize="13sp"
              android:gravity="center"
              android:layout_gravity="left"
              android:background="@drawable/tag"/>

    <ImageView android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:src="@drawable/ic_action_discard"
                 android:layout_marginLeft="10dp"
                 android:layout_gravity="right"
                 android:gravity="center"
                 android:scaleType="center"
                 android:alpha="0.5"/>
</LinearLayout>

看起来像这样:

enter image description here

标签补丁9如下所示:

enter image description here

我有3个问题:

  1. 如何使删除图标始终在右侧。
  2. 如何使标签图像的模糊部分正确缩放? (它的补丁9)
  3. 在标签旁边添加删除图标或使用某种长按是否更好?
  4. 谢谢。

2 个答案:

答案 0 :(得分:4)

  

如何使删除图标始终在右侧。

使用RelativeLayout代替LinearLayout并使用属性android:layout_alignParentRIght="true"。左右layout_gravity在横向LinearLayout中不执行任何操作,因为ViewGroup已经从左到右放置View

  

如何使标签图像的模糊部分正确缩放? (它的补丁9)

在不了解图像的情况下不确定,但应与其他图像相同。

  

在标签旁边添加删除图标或使用某种长按是否更好?

我认为这与使用您的应用的用户有关。我认为删除图标很好,更明确。但是,现在大多数用户,特别是年轻用户可能会了解长按,具体取决于整个应用的工作方式。但是,既然你有房间,我认为删除图标可能不错。

答案 1 :(得分:0)

How to make the delete icon always on the right.

在xml项目布局中,对于删除图标的imageview,添加android:layout_weight="0"

How to make the blurry part of the tag image scale properly? (its a patch 9)
抱歉,不知道

Is it better to have a delete icon next to the tag, or use some sort of long click?

取决于应用程序,如果除了删除之外还有其他选项,则可以长按所有选项,否则请保留图标,恕我直言

相关问题