0

リニアレイアウト内の評価バーとテキストビューを水平方向に中央揃えにしたい。評価バーがテキストビューよりも小さいようなもので、正しい配置が得られません。どうしよう???

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

<TextView
    android:id="@+id/author_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_below="@id/author_name"
    >

    <RatingBar
        android:id="@+id/rtbProductRating"
        style="@style/SmallRatingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:isIndicator="true"
        android:numStars="5"

        android:layout_marginBottom="@dimen/padding_text"
        android:layout_marginLeft="@dimen/padding_text"
        android:rating="0" />

    <TextView
        android:id="@+id/time"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/padding_text"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:textSize="18sp" >
    </TextView>
</LinearLayout>
<TextView
        android:id="@+id/texto"
        android:layout_below="@id/ll1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

4

4 に答える 4

0

線形レイアウトを使用すると、 android:gravity="center" を使用できます

次のレイアウトは、あなたが望むことを行うことができます:

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

<TextView
    android:id="@+id/author_name"
    android:text="d"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_below="@id/author_name"
    >

    <RatingBar
        android:id="@+id/rtbProductRating"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:isIndicator="true"
        android:numStars="5"
        android:rating="0" />

    <TextView
        android:id="@+id/time"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:text="sdf"
        android:textSize="18sp" >

]
    </TextView>
</LinearLayout>
<TextView
        android:id="@+id/texto"
        android:layout_below="@id/ll1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>
于 2013-11-07T09:15:49.777 に答える
0

私の意見では、Googleが示唆しているように、相対レイアウトでlinearlayoutを使用することはお勧めできません。次のように相対レイアウトのみを使用して実装できます。

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

<TextView
    android:id="@+id/author_name"
    android:text="d"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/texto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/author_name" />

<RatingBar
    android:id="@+id/rtbProductRating"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/texto"
    android:isIndicator="true"
    android:numStars="5"
    android:rating="0" />

<TextView
    android:id="@+id/time"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/texto"
    android:layout_toRightOf="@id/rtbProductRating"
    android:gravity="center_horizontal|center_vertical"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:text="asdf"
    android:textSize="18sp" />

</RelativeLayout>

残念ながら、RatingBar は textview よりも小さいと言う意味がわかりません! それらを中心に置くとどうなりますか?

于 2013-11-06T06:33:08.533 に答える
0

以下のコードを参照してください。自分の側でテストできるように少し変更しました。その正常に動作します。このコードを使用できます。適宜変更してください。

<?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="match_parent" >

    <TextView
        android:id="@+id/author_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/author_name"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <RatingBar
            android:id="@+id/rtbProductRating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            android:isIndicator="true"
            android:numStars="5"
            android:rating="0" />

        <TextView
            android:id="@+id/time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingBottom="8dp"
            android:paddingLeft="8dp"
            android:paddingRight="8dp"
            android:text="test"
            android:textColor="@color/white"
            android:textSize="18sp" >
        </TextView>
    </LinearLayout>

    <TextView
        android:id="@+id/texto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ll1" />

</RelativeLayout>
于 2013-11-06T07:18:05.073 に答える