![](/img/trans.png)
[英]How to show values other than the sample text that's on textView in Android
[英]Center textview, when other textview it's null (or dont have text)
我按照本教程進行操作,現在它運行良好,但我只有一個問題,我需要將“標題”textview 垂直居中,當“詳細信息”textview 文本時,它是 Z37A6259CC0C1DAE299A7866489
這是custom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/list"
android:layout_width="1px"
android:layout_height="1px"
android:layout_weight="1">
</ListView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="60dp"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<TextView
android:id="@+id/detail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/img"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee" />
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/img"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/detail"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:textColor="#ffffffff"
android:textSize="24sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
您使用android:layout_gravity
將實際文本視圖居中,並使用android:gravity
將文本視圖內的內容(如文本)居中。
示例 XML:
<TextView android:id="@+id/some_id"
android:text="Example text"
android:layout_height="70dp"
android:layout_width="wrap_content"
android:gravity="center_vertical" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.