0

LinearLayout 안에 RelativeLayout이 있습니다. 이 내부에는 ProgressBar 및 기타 요소가 있습니다.android ProgressBar가 부모 LinearLayout의 높이 치수를 변경 중입니다

현재 문제는 ProgressBar가 RelativeLayout 내부에 배치 될 때 부모 LinearLayout의 높이를 확장한다는 것입니다.

다음은 내가 가지고있는 기본 사항입니다. 이 ProgressBar의 높이에 의해 상위의 LinearLayout의 높이를 연장처럼

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_weight="1" 
    android:weightSum="2"> 

    <RelativeLayout 
     android:id="@+id/timer1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/darker_gray"> 

     <ProgressBar 
      android:layout_width="200dp" 
      android:layout_height="20dp" 
      style="@android:style/Widget.ProgressBar.Horizontal" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:layout_centerInParent="true"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/timer2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/holo_blue_light"/> 

</LinearLayout> 

ProgressBar를 보인다. 어느 것이 당연히 원하지 않는지.

위의 LinearLayout은 weightSum = "3"인 또 다른 수직 LinearLayout 내부에 있음을 명심하십시오. 따라서이 높이의 왜곡은 모든 것이 수직으로 화면에 맞지 않음을 의미합니다.

내가 생각할 수있는 한 가지 결함은 코드가 아직 완성되지 않았기 때문에 (3 단계 각각에 ProgressBar를 넣지 않음) 단지 버크 (quirk)라는 것입니다. 내가하고 다시보고 할게. 하지만 여전히 나에게 이것은 좋은 일이 될 수없는 것처럼 보입니다.

+0

첫 번째 상대 레이아웃의 _android : layout_height = "wrap_content"_을 변경하십시오. 그냥 시도해보십시오. 확실하지 않습니다. –

답변

0
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 

    <RelativeLayout 
     android:id="@+id/timer1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/darker_gray"> 

     <ProgressBar 
      android:layout_width="200dp" 
      android:layout_height="20dp" 
      style="@android:style/Widget.ProgressBar.Horizontal" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:layout_centerInParent="true"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/timer2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/holo_blue_light"/> 

</LinearLayout> 



when using weights use the width or the height to 0dp which ever orientation u need 
0

글쎄요. 위의 예제 코드에서는 보이지 않는 외부 LinearLayout의 세 가지 레벨을 모두 채운 후에 레이아웃이 스스로를 정렬하는 것처럼 보였다.

모든 높이 매개 변수는 동일하며 (각각 화면 높이의 3 분의 1을 차지함) xml 미리보기 창과 에뮬레이터에서 테스트 한 경우 모두 마찬가지입니다.

그래서 3의 weightSum을 가진다면 레이아웃이 실제로 3 개의 모든 체중 구분을위한 코드를 작성할 때까지 균형이 맞지 않을 것입니다.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:wieghtSum="3" > 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
<LinearLayout/> 

을하지만 코드가 불완전하기 때문에 다음은 잠재적 텍스트 뷰의 왜곡 된 높이를 보여줄 것이다 :

예를 들어,이 작동합니다. weightSum은 3으로 설정되어 있지만 세 부분 중 두 개의 코드 만 작성됩니다.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:wieghtSum="3" > 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
<LinearLayout/> 
관련 문제