Android:在LinearLayout中将ImageView右对齐 [英] Android: Right-Aligning ImageView in LinearLayout

查看:98
本文介绍了Android:在LinearLayout中将ImageView右对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

imageView在此linearlayout布局中未获得右对齐(如果重要的话,此LinearLayout实际上是列表中的一行).

The imageView is not getting right-aligned in this linearlayout (If it matters this LinearLayout is actually a row in a list).

但是,如果我使用TextView(在下面的代码中注释了它)而不是ImageView,它将成功右对齐.

But if i use a TextView (its commented in code below) instead of ImageView, it successfully gets right-aligned.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="#FFFFAA"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textAppearance="?android:attr/textAppearanceMedium" />

<!--
    <TextView
        android:id="@+id/labelNext"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="right"
        android:text="> "
        android:textSize="20sp" 
        android:textStyle="bold">
    </TextView>
-->

     <ImageView
        android:id="@+id/iconNext"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:gravity="right"
        android:src="@drawable/right_arrow" >
    </ImageView>     
</LinearLayout>

如何将imageView放置在LinearLayout行的最右边?

How do i get the imageView to the right-most edge of the LinearLayout row?

推荐答案

使用RelativeLayout代替LinearLayout,因为LinearLayout不支持它. 像这样使用:

Use a RelativeLayout instead of LinearLayout because LinearLayout does not support it. Use like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="#FFFFAA" >

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textAppearance="?android:attr/textAppearanceMedium" />

     <ImageView
        android:id="@+id/iconNext"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:layout_alignParentRight="true"
        android:src="@drawable/right_arrow" >
    </ImageView>     
</RelativeLayout>

这篇关于Android:在LinearLayout中将ImageView右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆