0

android:weightSum이 필수인지 여부는 android:layout_weight일까요? 없이 android:layout_weightlinearlayout 내부에 직접 사용할 수 있습니까? 누구든지 android:layout_weight을 사용하고, android:weightSum을 사용하지 않고 장단점을 말해주십시오. 미리 감사드립니다.안드로이드를 추가하지 않고 android : layout_weight를 사용할 수 있습니까? 그렇다면 문제는 무엇입니까?

샘플 코드 : 부모에게 weightSum : 안드로이드를 추가하지 않고에 layout_weight :

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/table_view" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="8dp" 
      android:orientation="horizontal"> 

      <Button 
       android:id="@+id/button_1" 
       style="@style/BaseButtonStyle" 
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:text="@string/start" /> 

      <Button 
       android:id="@+id/button_2" 
       style="@style/BaseButtonStyle" 
       android:layout_width="0dp" 
       android:layout_height="36dp" 
       android:layout_weight="1" 
       android:text="@string/pause" 
       android:textColor="@color/teal" /> 

      <Button 
       android:id="@+id/button_3" 
       style="@style/BaseButtonStyle" 
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:text="@string/stop" /> 
     </LinearLayout> 

답변

0

우리가 안드로이드를 사용할 수 있습니까?

예, 수 있습니다. 아래의 예를 고려 -

Consider this example,

이 경우 오른쪽에 TextViewImageButton을 가지고있다 Terms & Condition 같은 행을 설계합니다.

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="8dp" 
     android:orientation="horizontal"> 

     <!-- Width of TextView = Width of LinearLayout - width of ImageButton --> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="?selectableItemBackgroundBorderless" 
      android:src="@drawable/ic_vector_back_black_18dp"/> 

    </LinearLayout> 

WeightSum의 개념를 들어, 당신은이 SO link

+0

내 생각에 LinearLayout이 weighSum 속성을 설정하지 않습니다. 그러나 아이들은 같은 가중치 또는 다른 가중치를 가진 android : layout_weight을 가지고 있습니다. 귀하의 예에서는 오직 한 명의 자녀가 android : layout_weight를 가지고 있습니다. 모든 아이는 체중을가집니다. LinearLayout에는 체중이 없습니다 .Sum. – Praveen2Gemini

+0

다중 가중치를 사용하는 경우 시스템이 측정 할 수 있도록 'weightSum'을 정의해야합니다. 상위 (사례)에 따라 높이 또는 너비를 측정합니다. 한 아이를 갖기를 원할 때, 특정 아이에게 체중을 사용하면 나머지 아이가 자동으로 자신의 차원을 차지하게됩니다 (나의 경우). – Wizard

0

그래, 우리가 부모의 체중 합계를 정의하지 않고 무게를 사용할 수 있습니다 참조 할 수 있습니다 : - 그것은 것처럼 간다. 이 경우 아동의 총 체중은 각 아동의 체중을 더하여 계산됩니다.

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

    <ImageView 
     android:layout_height="wrap_content"  
     android:layout_weight="1" 
     android:layout_width="0dp"/> 

    <ImageView 
     android:layout_height="wrap_content"  
     android:layout_weight="1" 
     android:layout_width="0dp"/> 

    <ImageView 
     android:layout_height="wrap_content"  
     android:layout_weight="1" 
     android:layout_width="0dp"/> 
</LinearLayout> 

부모 레이아웃이 자동으로 3 (각 아이의 무게의 합)

여기이 주제에 대한 더 많은 자원이기 때문에 무게의 합계를 취할 것

What is android:weightSum in android, and how does it work?

https://developer.android.com/reference/android/widget/LinearLayout.html

관련 문제