2012-05-20 5 views
0

ProgressBar가 맨 오른쪽보기와 겹치지 않게하려면 어떻게해야합니까? TableLayout을 사용하고 싶지는 않습니다. 나는 또한이 우수한 SOF link을 이미 읽었습니다.ProgressBar가 RelativeLayout의 맨 오른쪽보기와 겹치지 않게 유지

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> 

답변

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의에 싸여 textviews을 왜, 나는 이것이 당신의 부분에 오해가있을 수 있습니다 생각 , 당신이 Textviews 자신을 왼쪽과 오른쪽으로 강제로 할 수있는 것처럼

+0

이것은 작동합니다! 귀하의 질문에 대답하기 위해, 나는 "rel_left"와 "RIGHT"에 또 다른 TextView를 추가 할 것이기 때문에 그들 자신의 RelativeLayout에 싸여 있습니다. – AG1

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> 
관련 문제