2013-03-15 2 views
0

선형 레이아웃을 배우고 있는데 혼란이 있습니다.android의 선형 레이아웃 arangment

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".MainActivity" > 


    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" 
     android:layout_weight=".33"/> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_weight=".33"/> 


    <Button 
     android:id="@+id/button2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_weight=".3"/> 


</LinearLayout> 

이 코드에는 세 가지 요소가 있습니다.

  1. 텍스트 뷰 2. 3. Button1을 Button2를

선형 배열 방향이 수직이고, I는 그들을 하나 개의 가중치 값을 조정 동일한 가중치를 부여했다.

이제 수직 방향으로 나는 그래서 높이와 너비를 모두 채우는

android:layout_width="fill_parent" 
android:layout_height="wrap_content" 

을 제공하고 있어요.

하지만 수평 레이아웃을 사용하고 그것은 폭을 채우는

android:layout_height="fill_parent" 
    android:layout_width="wrap_content" 

처럼 쓰고 있지만

높이

을 채우는 대신 안드로이드를 포기하지 않을거야 때 : layout_height = "fill_parent는"왜 높이를 작성하지?

답변

0

복사이 코드를 붙여 넣으면 시도해보십시오. 높이가 채워집니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    tools:context=".MainActivity" > 


    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="@string/hello_world" 
     android:layout_weight=".33"/> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="Button" 
     android:layout_weight=".33"/> 


    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="Button" 
     android:layout_weight=".3"/> 


</LinearLayout> 
+0

은 당신이 만든 어떤 변화가 뜻이 게시물을 참조 나에게 난 그냥 방향을 변경 –

+0

아무것도 말할하십시오 - 수평 및이 두 줄을 각보기 안드로이드 : layout_width = "wrap_content" android : layout_height = "fill_parent" – Nirali

0

나는 당신이 코드를 던지는 사람 대신이 주제에 대해 이해해야한다고 생각합니다. 작업 코드는 위의 @Nirali에 표시된 것과 같습니다.

그래서이 충돌 과정에서는 fill_parent와 wrap_content가 무엇인지 이해해야합니다. 선형 레이아웃은 부모님이거나 기기의 화면으로 볼 수 있습니다. 높이를 fill_parent로 설정하면 화면의 전체 높이가 채워집니다.

Wrap_content는 개체 (예 : 단추)를 래핑하는 것입니다. height를 wrap_content로 설정하면 버튼을 멋지게 배치하는 높이가 설정됩니다.

위가 더 나은 이해를 위해, 내 머리 벗기 설명, 당신이 무슨 짓을 What's the difference between fill_parent and wrap_content?

+0

그래, 내가이 레이아웃을 배우고 있다는 것을 알고있다. 나는 왜 내가 그걸 물었 을까하는 해결책을 얻지 못하고있다. –

+0

도와 드리겠습니다. 일단 기본을 이해하면 많은 것을 만들 수 있습니다. 행복한 코딩. –

+0

제안 해 주셔서 감사합니다. –