0

ProgressBarが右端のビューと重ならないようにするにはどうすればよいですか?TableLayoutを使用したくないことに注意してください。この優れたSOFリンクもすでに読んでいます。

ProgressBar_overlap

<?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="fill_parent"
android:padding="10dp" >

<RelativeLayout
    android:id="@+id/rel_left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="LLL" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/RIGHT"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="RRR" />
</RelativeLayout>

<ProgressBar
    android:id="@+id/pb"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="5sp"
    android:layout_toRightOf="@+id/rel_left"
    android:max="100"
    android:progress="80" />

</RelativeLayout>
4

2 に答える 2

2

これでうまくいくはずです:

<?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="fill_parent"
android:padding="10dp" >
    <!-- Align parent left cause this textview to be on the left! -->
    <TextView
        android:id="@+id/left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="LLL" />

    <!-- Align parent right cause this textview to be on the right! -->
    <TextView
        android:id="@+id/right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="RRR" />

    <!-- Now we want this progressbar to take up all the space in between. Just specify the 'layout_toLeftOf' and 'layout_toRightOf' properites! -->
    <ProgressBar
        android:id="@+id/pb"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="5sp"
        android:layout_toRightOf="@+id/left"
        android:layout_toLeftOf="@+id/right"
        android:max="100"
        android:progress="80" />

</RelativeLayout>

テキストビューを独自のRelativeLayoutでラップしている理由がわかりません。テキストビュー自体を左右に強制できるため、これは誤解である可能性があります。

于 2012-05-20T03:05:10.637 に答える
1

これが、RelativeLayoutに5つのアイテムがある場合の私の解決策です。

<?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="fill_parent"
android:padding="10dp" >

<!-- Align parent left cause this TextView to be on the left! -->

<TextView
    android:id="@+id/left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:text="LLL" />

<TextView
    android:id="@+id/left_number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5sp"
    android:layout_toRightOf="@+id/left"
    android:text="100" />

<!-- Align parent right cause this TextView to be on the right! -->

<TextView
    android:id="@+id/right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:text="RRR" />

<TextView
    android:id="@+id/right_number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="5sp"
    android:layout_toLeftOf="@+id/right"
    android:text="2" />

<!-- Now we want this ProgressBar to take up all the space in between. Just specify the 'layout_toLeftOf' and 'layout_toRightOf' properites! -->

<ProgressBar
    android:id="@+id/pb"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="5sp"
    android:layout_toLeftOf="@+id/right_number"
    android:layout_toRightOf="@+id/left_number"
    android:max="100"
    android:paddingLeft="5sp"
    android:paddingRight="5sp"
    android:progress="80" />

</RelativeLayout>
于 2012-05-20T20:43:56.253 に答える