2012-02-01 2 views
0

내 이미지 버튼의 높이가 40 픽셀이지만 갤러리 높이가 훨씬 큽니다. 바로 지금, 내 이미지 버튼은 주어진 공간 전체를 차지하며 내 갤러리와 같은 높이입니다. 이 가로 배치를 유지하면서 버튼을 원래 크기로 유지할 수 있습니까?다른 높이의 차일드가있는 layout_weights가있는 LinearLayout

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:orientation="horizontal" 
     android:paddingTop="20dp" > 

     <ImageButton 
      android:id="@+id/left_arrow" 
      android:layout_weight="3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/shared_arrow_left_button_selector" 
      android:scaleType="fitCenter" /> 

     <Gallery 
      android:id="@+id/gallery" 
      android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:layout_weight="1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:spacing="15dp" /> 

     <ImageButton 
      android:id="@+id/right_arrow" 
      android:layout_weight="3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/shared_arrow_right_button_selector" 
      android:scaleType="fitCenter" /> 
    </LinearLayout> 
+1

LinearLayout의 시작 태그를 추가하여 이해할 수 있습니까? – Badal

+0

또한 스크린 샷을 업데이트하고 있습니다 ... – MKJParekh

답변

0

당신은

android:layout_width="match_parent" 
android:layout_height="match_parent" 

을 적용하는 모두 ImageButtons에 방금 ImageButtons 원래 크기가 단지 wrap_content으로 변경 랩과 layout_weight을 제거하려면 그들이 높이를 작성되도록 재산. 갤러리에 layout_weight="1"을 적용 할 때 너비는 layout_weight 속성 자체로 관리되므로 android:layout_width="0dp"으로 변경하십시오. 최종 레이아웃은 다음과 같아야합니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:paddingTop="20dp" > 

    <ImageButton 
     android:id="@+id/left_arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitCenter" /> 

    <Gallery 
     android:id="@+id/gallery" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:spacing="15dp" /> 

    <ImageButton 
     android:id="@+id/right_arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitCenter" /> 

</LinearLayout> 
0

ImageButtons에서 레이아웃 가중치 = 3을 제거하면 갤러리보다 이미지 버튼이 더 크게 표시됩니다.

나는이 문제를 해결하는 방법을 알지 못하도록 layout_weight 속성을 사용하는 법을 모른다고 생각합니다. 먼저 layout_weight에 대해 알고 있습니다.

언제든지 저에게 물어보십시오.

이미지 버튼과 갤러리에서 다음 줄을 사용하면 멋지게 보일 것입니다.

android:layout_weight="1" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
+0

동적으로 뷰의 너비를 조정하는 데 가중치가 사용 된 것 같습니다. – Raptrex

0
<ImageButton 
     android:id="@+id/left_arrow" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/shared_arrow_left_button_selector" 
     android:scaleType="centerinside" /> 
Remove Weight attribute, and set width and height of buttons to wrap_content 
    <Gallery 
     android:id="@+id/gallery" 
     android:focusable="true" 
    android:focusableInTouchMode="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:spacing="15dp" /> 

    <ImageButton 
     android:id="@+id/right_arrow" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/shared_arrow_right_button_selector" 
     android:scaleType="centerinside" /> 
</LinearLayout>