2013-10-18 1 views
1

안녕하세요.LinearLayout의 LinearLayout에는 3 요소가 있습니다. 하나는 왼쪽에, 하나는 가운데에, 다른 하나는 오른쪽에 맞 춥니 다.

저는 1 시간 넘게이 작업을하고 있습니다. 제대로 작동하지 않습니다. 나는 다음과 같아야 레이아웃을 만들려면 :

enter image description here

내가 왼쪽으로 alligned 텍스트 뷰, 중심 ProgressBar의 오른쪽에 alligned 다른 텍스트 뷰를 가지고 싶습니다. 레이아웃이 다른 장치에 사용되어야하기 때문에 정적 너비를 사용하고 싶지 않습니다. enter image description here

내가 구글을 통해 모든 솔루션을 찾을 수 없습니다, 그래서 어떤 도움이 정말 감사합니다 :

는 불행하게도 내 레이아웃은 순간 다음과 같습니다. 이 내 레이아웃입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/txtProgress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="TextView" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="25sp" 
      android:layout_marginRight="5sp" 
      android:gravity="center" 
      android:text="0 %" /> 

     <ProgressBar 
      android:id="@+id/progressBar1" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.36" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="right" 
      android:layout_marginLeft="5sp" 
      android:layout_marginRight="25sp" 
      android:gravity="right" 
      android:text="100 %" /> 
    </LinearLayout> 

</LinearLayout> 

답변

2

당신은 잘 할 수 있습니다 시도하는 RelativeLayout과 같이 : 이런 식으로 뭔가를 생산

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <TextView 
     android:id="@+id/yourTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="20pt" 
     android:text="TextView" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/yourTitle"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="25sp" 
      android:layout_marginRight="5sp" 
      android:gravity="center" 
      android:text="0 %" /> 

     <ProgressBar 
      android:id="@+id/progressBar1" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.36" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="right" 
      android:layout_marginLeft="5sp" 
      android:layout_marginRight="25sp" 
      android:gravity="right" 
      android:text="100 %" /> 
     </LinearLayout> 

</RelativeLayout> 

:

Image of layout from emulator

1

나는했습니다 단지 텍스트보기에 weight을 추가하고 설정하십시오. width 0dp

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/txtProgress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="TextView" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="25sp" 
      android:layout_marginRight="5sp" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="0 %" /> 

     <ProgressBar 
      android:id="@+id/progressBar1" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="5" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="right" 
      android:layout_marginLeft="5sp" 
      android:layout_marginRight="25sp" 
      android:layout_weight="1.2" 
      android:gravity="right" 
      android:text="100 %" /> 
    </LinearLayout> 

</LinearLayout> 
1

코드를 시도했는데 올바르게 작동합니다. 하지만 android:layout_width을 사용해 ProgressBar에서 0 디핑을 시도 할 수 있습니다.

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 
관련 문제