如何使文本位于列表的最右侧 android
how to make text go to the far right on a list android
如何让图像中的位置(Westonaria)在列表视图中位于 "cell" 的最右侧?
这是我当前的代码,我第一次尝试硬编码空格(我知道这很糟糕)但也尝试了 android:layout_theEndof="@id/currencyTxt" 例如?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp" >
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iconImg"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginRight="50dp"/>
<TextView
android:id="@+id/titleTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iconImg"
android:textSize="30sp"
android:textStyle="bold"
/><!--done-->
<TextView
android:id="@+id/userAliasTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iconImg"
android:textSize="12sp"
android:layout_below="@id/titleTxt"
/> <!--done-->
<TextView
android:id="@+id/spacer"
android:text=" "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/userAliasTxt"
android:textSize="16sp"
android:textStyle="bold"
/><!--done-->
<TextView
android:id="@+id/currencyTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iconImg"
android:layout_below="@id/spacer"
android:textSize="20sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#E69611"
/><!--done-->
<TextView
android:id="@+id/amountTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/currencyTxt"
android:textSize="20sp"
android:textColor="#E69611"
android:textStyle="bold"
android:layout_below="@id/spacer"
/><!--done-->
<TextView
android:id="@+id/spacer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/spacer"
android:layout_toRightOf="@id/amountTxt"
android:textSize="20sp"
android:textStyle="bold"
/><!--done-->
<TextView
android:id="@+id/locationTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_below="@id/currencyTxt"
android:layout_toRightOf="@id/iconImg"
/><!--done-->
</RelativeLayout>
感谢您的帮助
试试这个:
使用标准 ArrayAdapter
然后你可以使用构造函数:
ArrayAdapter<String>(Context, R.layout.aligned_right, values);
其中 R.layout.aligned_right
是这样的 xml 布局:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="right"/>
编辑
您需要添加这两个属性,因为 alignParentEnd
目标是更高的 API 级别,而 alignParentRight
目标是更低的 API 级别。根据您的最低 SDK 级别,您需要决定要使用哪些属性。
原答案
在文本视图中包含以下内容:
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
阅读 docs :)
设置父布局宽度Match_Parent
使价格文本视图宽度 Match_Parent
现在价格 textview
android:alignParentRight="ture"
如何让图像中的位置(Westonaria)在列表视图中位于 "cell" 的最右侧?
这是我当前的代码,我第一次尝试硬编码空格(我知道这很糟糕)但也尝试了 android:layout_theEndof="@id/currencyTxt" 例如?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp" >
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iconImg"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginRight="50dp"/>
<TextView
android:id="@+id/titleTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iconImg"
android:textSize="30sp"
android:textStyle="bold"
/><!--done-->
<TextView
android:id="@+id/userAliasTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iconImg"
android:textSize="12sp"
android:layout_below="@id/titleTxt"
/> <!--done-->
<TextView
android:id="@+id/spacer"
android:text=" "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/userAliasTxt"
android:textSize="16sp"
android:textStyle="bold"
/><!--done-->
<TextView
android:id="@+id/currencyTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iconImg"
android:layout_below="@id/spacer"
android:textSize="20sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#E69611"
/><!--done-->
<TextView
android:id="@+id/amountTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/currencyTxt"
android:textSize="20sp"
android:textColor="#E69611"
android:textStyle="bold"
android:layout_below="@id/spacer"
/><!--done-->
<TextView
android:id="@+id/spacer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/spacer"
android:layout_toRightOf="@id/amountTxt"
android:textSize="20sp"
android:textStyle="bold"
/><!--done-->
<TextView
android:id="@+id/locationTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_below="@id/currencyTxt"
android:layout_toRightOf="@id/iconImg"
/><!--done-->
</RelativeLayout>
感谢您的帮助
试试这个:
使用标准 ArrayAdapter
然后你可以使用构造函数:
ArrayAdapter<String>(Context, R.layout.aligned_right, values);
其中 R.layout.aligned_right
是这样的 xml 布局:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="right"/>
编辑
您需要添加这两个属性,因为 alignParentEnd
目标是更高的 API 级别,而 alignParentRight
目标是更低的 API 级别。根据您的最低 SDK 级别,您需要决定要使用哪些属性。
原答案
在文本视图中包含以下内容:
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
阅读 docs :)
设置父布局宽度Match_Parent 使价格文本视图宽度 Match_Parent 现在价格 textview
android:alignParentRight="ture"