2014-05-21 3 views
0

layout_weight 태그는 폭을 기준으로 폭을 설정하는 데 도움이됩니다. 신장 조절과 같은 것이 있습니까? 초보자가 도와주세요. :)화면 높이에 상대적으로 이미지 뷰의 높이를 설정할 수있는 방법이 있습니까

<?xml version="1.0" encoding="utf-8"?> 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="0dip" android:layout_gravity="top" 
    > 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="5dp" 
    android:paddingLeft="10dp" 
    android:paddingTop="5dp" 
    > 
    <ImageView 
    android:id="@+id/image" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_gravity="left|top" 
    android:scaleType="centerCrop" 
    android:src="@drawable/ic_launcher" /> 
    <ImageView 
    android:id="@+id/imaget" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left|top" 
    android:layout_weight="1" 
    android:scaleType="centerCrop" 
    android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 
    </TableLayout> 
+0

은 모두 이미지 뷰 – Opiatefuchs

+0

무엇 × 2 레이아웃 – user3407787

+0

무게 = 0.25로 설정 커야한다보기를 원한다면 내가 = 무게로 작은 하나, 어떻게해야 0.75 – Opiatefuchs

답변

0

변화에이 줄을

android:layout_height="wrap_content" 

: 당신의 LinearLayout에 무게를 사용할 수 있습니다

android:layout_height="fill_parent" 
android:scaleType="fitStart" 
0

.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="5dp" 
    android:paddingLeft="10dp" 
    android:paddingTop="5dp" 
    android:orientation="vertical" 
    android:weightSum="1.0"> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     android:layout_gravity="left|top" 
     android:scaleType="centerCrop" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/imaget" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_gravity="left|top" 
     android:layout_weight="0.5" 
     android:scaleType="centerCrop" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

설정하면 android:layout_weight 이미지의 높이를 설정할 수 있습니다.

0

다양한 방법이 있습니다. 따라야 할 것이지만 때로는 상황에 달려 있습니다. xml에서 fill_parent or match_parent을 선언하여 처리 할 수 ​​있습니다. 또한 LinearLayout을 사용하고 그 자식을 weight으로 설정하여 처리 할 수 ​​있습니다.

또는 상황을 동적으로 처리 할 수 ​​있습니다. 단추가 있고 화면 중간에 단추를 넣고 싶다고 가정 해보십시오. 그 상황에서 화면의 너비와 높이를 동적으로 계산하고 높이와 너비를 2로 나누어야합니다. 그리고 계산 된 너비와 높이를 버튼에 설정해야합니다.

관련 문제