2011-11-02 1 views
1

'LinearLayout'을 사용하고 4 개의 컨트롤을 추가합니다.레이아웃에 추가 한 컨트롤의 질량을 피하는 방법은 무엇입니까?

 1. textView_1 - that contain the title of the application 
     2. textView_2 - that contain some dynamic text 
     3. Button  - that contain the title of the application 
     4. ImageView - that contain the application logo (image) 

내 질문

어떻게 내가 그 모든 컨트롤 사이의 관계를 유지할 수 있습니까? 첫 번째 컨트롤을 화면의 10 %, 두 번째 컨트롤을 60 %, 세 번째 컨트롤을 20 %, 마지막 컨트롤을 10 %로 만들고 싶습니다.

또한 textview의 글꼴을 동적으로 유지하고 싶습니다. 응용 프로그램을 큰 화면 (태블릿)에서 실행하면 글꼴 크기가 화면 크기에 따라 커집니다.

답변

3

공간을 분배하기 위해 layout_weight를 사용하십시오.

<LinearLayout 
    android:orientation="vertical" 
> 
    <TextView 
    android:layout_height="0dp" 
    android:layout_weight="0.1" 
    /> 
    <TextView 
    android:layout_height="0dp" 
    android:layout_weight="0.6" 
    /> 
    <Button 
    android:layout_height="0dp" 
    android:layout_weight="0.2" 
    /> 
    <ImageView 
    android:layout_height="0dp" 
    android:layout_weight="0.1" 
    /> 
</LinearLayout> 

글꼴 크기를 조절하려면 "sp"를 사용해보세요.

+0

감사합니다. 동적 글꼴 크기는 어떻습니까? – Yanshof

+0

sry, 그 사실을 알지 못한다면, 내가 아는 한 일찍 언급했을 것이다. –

+0

당신은 "sp"로 시도해 볼 수 있습니다. "dp"와 유사합니다. 글꼴 크기가 늘어날 것입니다. 시도하지 말고 항상 시도해보십시오. 이게 효과가 있으면 알 수 있도록 대답에 포함시킬 수 있습니다. –

1

LinearLayout의 무게 속성을 사용하여 공간 분배를 달성 할 수 있습니다. 외부 선형 레이아웃을 android:weightSum=1.0으로 지정하고 높이와 너비를 fill_parent으로 설정하십시오. 그런 다음 각 어린이에게 0dp 값과 0 미만의 값을 갖는 android:layout_weight 속성을 가진 android:layout_height 속성을 봅니다. 총 가중치 합이 1.0이고 1.0이 100 %이므로 값을 백분율로 사용할 수 있습니다. 자녀에게 android:layout_weight=0.1을 주면 신장의 10 %를 차지합니다.

하지만 텍스트 크기 자동 조정이 가능한지 확실하지 않습니다. 이를 위해 사용자 정의보기를 작성해야 할 수도 있습니다.

1

android : layout_weight 태그를 사용하면 백분율을 지정할 수 있습니다. 벨로우즈 예제에서 두 개의 버튼은 각각 사용 가능한 공간의 40 %와 60 %를 차지합니다.

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="1.0" > 

    <Button 
     android:text="left" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight=".60" /> 

    <Button 
     android:text="right" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight=".40" /> 

</LinearLayout> 
관련 문제