2009-07-24 3 views
69

비디오 타이틀과 태그를 표시하는 대화 상자를 만들고 싶습니다. 텍스트 아래에보기, 편집 및 삭제 버튼을 추가하고 이러한 요소를 같은 크기로 만듭니다. 누구든지 .xml 레이아웃 파일을 수정하여 LinearView 내부의 요소를 동일한 크기로 만드는 방법을 알고 있습니까?안드로이드 : LinearLayout 내부의 모든 요소를 ​​같은 크기로 만드는 방법?

현재의 레이아웃 파일은 다음과 같습니다 : 누군가가 붙여 넣은 파일 내용을 수정하여 솔루션을 보여줄 수 있다면 감사하겠습니다

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/txtTitle" android:text="[Title]" > 
      </TextView> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/txtTags"    
       android:text="[Tags]" > 
      </TextView> 

    </LinearLayout> 

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

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnPlay" 
      android:text="View"> 
     </Button> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnEdit" 
      android:text="Edit"> 
     </Button> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnDelete" 
      android:text="Delete"> 
     </Button> 

    </LinearLayout> 

</LinearLayout> 

.

감사합니다.

답변

148

Buttonandroid:layout_width="0px"android:layout_weight="1"을 사용하십시오. 버튼은 0 픽셀을 넘지 않아야하지만 3 개는 버튼 사이에 여분의 공간을 나누어야한다고합니다. 그렇게하면 원하는 시각적 효과를 얻을 수 있습니다.

+4

_REALLY_ 싶으면 android : stretchColumns = "0,1,2"와 함께 TableLayout을 사용할 수 있습니다. –

+0

굉장한 ... 그래서 우리가 너비를 0px로 설정하면 가중치가 설정을 무시하게됩니까? 왜 그래야만하지? – noob

+0

이것은 완벽하게 작동했습니다. – Proverbio

28

또 다른 방법은 android:layout_width="fill_parent"android:layout_weight="1"도 잘 작동합니다!

+13

당신은이 대답에 정말로 흥분했습니다. :-) 열정을 사랑해! –

+0

CommonsWare의 솔루션이 나에게 도움이되지 못했지만 그랬습니다! :) "fill_parent"보다 선호해야한다고 들었으므로 "match_parent"를 사용했지만 둘 다 작동합니다. – codepleb

1

저는 귀하의 문제를 해결할 것이라고 생각하는 EqualSpaceLayout을 작성했습니다. 이것은 LinearLayout과 비슷하지만 자식 뷰의 크기를 왜곡하지 않습니다. 그것을 확인해보십시오 : http://www.dev-smart.com/archives/225

16

weightSum을 가진 LinearLayout을 사용하고 같은 요소를 가진 요소를 만듭니다. layout_weight. 여기서 일례는 ...

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="5"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_share_white_36dp"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_search_white_36dp"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_event_note_white_36dp"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_brush_white_36dp"/> 

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

그래서, 모든 요소의 가중 합계는 Google Material Design 아이콘이 사용

enter image description here

참고 것을 ... 여기 5 인 스크린 샷이다. 희망이 도움이됩니다.

관련 문제