简体   繁体   中英

How to right align in linear layout

I have this layout as my list items:

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

It looks like this:

在此处输入图片说明

The tag patch 9 looks like so:

在此处输入图片说明

I have 3 questions:

  1. How to make the delete icon always on the right.
  2. How to make the blurry part of the tag image scale properly? (its a patch 9)
  3. Is it better to have a delete icon next to the tag, or use some sort of long click?

Thank you.

How to make the delete icon always on the right.

Use RelativeLayout instead of LinearLayout and use the property android:layout_alignParentRIght="true" . left and right layout_gravity does nothing in a horizontal LinearLayout since that ViewGroup already lays View s out from left to right.

How to make the blurry part of the tag image scale properly? (its a patch 9)

Not sure without knowing more about the image but should be the same as the other image.

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

This is relative to the users who will use your app, I suppose. The delete icon I think is fine and is more explicit. However, most users nowadays, especially younger ones may understand to long click depending on how your whole app works. However, since you have the room, I think the delete icon is probably good.

How to make the delete icon always on the right.

in your xml item layout, for your imageview of the delete icon, add android:layout_weight="0"

How to make the blurry part of the tag image scale properly? (its a patch 9)

sorry, no idea

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

depends on the app, if there will be other options other than delete, then make all of them in long click, otherwise leave the icon, IMHO

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