5

下の画像では、赤のテキストビューを垂直方向に中央揃えにしたいのですが、LinearLayout ではなく RelativeLayout だけを使い続けたいと思います。LinearLayout でこれを行う方法を理解できると思いますが、これらを使用したくありません。

これはすべて、私がここで見つけた例に基づいていますAndroid devleper's blog - Android Layout Tricks #1

代替テキスト

ここに私のxmlがあります

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip">

    <ImageView android:id="@+id/icon" android:layout_width="wrap_content"
        android:layout_height="fill_parent" 
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true"
        android:src="@drawable/chevron" />



    <TextView android:id="@+id/rightText" android:layout_width="55px"
        android:layout_height="fill_parent" android:layout_toLeftOf="@id/icon"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:textSize="14dip"
        android:text="$15.99" />


    <TextView android:id="@+id/secondLine" android:layout_width="wrap_content"
        android:layout_height="26dip" android:layout_toLeftOf="@id/rightText"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" 
        android:text="Simple application that shows how to use RelativeLayout" />

    <TextView android:layout_width="fill_parent" android:id="@+id/firstLine"
        android:layout_height="wrap_content" android:layout_toLeftOf="@id/rightText"
        android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
        android:layout_above="@id/secondLine"
        android:layout_alignWithParentIfMissing="true" android:gravity="center_vertical"
        android:singleLine="true"
        android:ellipsize="end"
        android:maxLines="1"
        android:textSize="13dip"
        android:text="My Application that has a really long title  asdfsdf asdf sdf asdf" />

</RelativeLayout>
4

2 に答える 2

7

の重力を設定するだけですTextView

于 2010-07-09T20:02:01.000 に答える
3

上記の答えがうまくいかない場合、他の人にとっては完全に役立つかもしれません。以下の属性を textView に設定するだけです

 android:layout_centerVertical="true"
于 2017-01-06T10:51:46.207 に答える