2013-08-02 2 views
1

LinearLayout (비디오 버튼 컨테이너)과 이미지 버튼이 자식입니다. 해당 비디오 버튼을 오른쪽 정렬해야하므로 layout_gravity="right"으로 지정했습니다.Android 선형 레이아웃 방향이 레이아웃 중력에 미치는 영향은 무엇입니까?

enter image description here

내가 원하는 것은 이것이다 :

<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" > 

    <!-- VIDEO BUTTON CONTAINER --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:background="#000000" 
     android:layout_gravity="top"> 

     <!-- VIDEO BUTTON --> 
     <ImageButton 
      android:id="@+id/button_video" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="?android:attr/selectableItemBackground" 
      android:contentDescription="@string/desc" 
      android:paddingBottom="@dimen/controls_button_padding" 
      android:paddingTop="@dimen/controls_button_padding" 
      android:src="@drawable/ic_action_video" /> 
    </LinearLayout> 

    <!-- some FrameLayout and another LinearLayout --> 
</LinearLayout> 

그것은이 생산

enter image description here

를 내가 얻을 변경하여 비디오 버튼 컨테이너의 android:orientation="horizontal"android:orientation="vertical"에가. 무슨 일이 있었습니까? 컨테이너의 수평 방향으로 작동하지 않는 이유는 무엇입니까?

답변

7

컨테이너가 가로 인 경우 왼쪽에서 오른쪽으로 순서대로 요소를 스택하는 것으로 가정합니다. 그렇다면 원래의 전제를 유지하면서 레이아웃 중력을 수평 적으로 어떻게 충족시킬 수 있습니까?

가로 중력 (오른쪽, 왼쪽, 가운데)은 세로 LinearLayout에서 작동하고 세로 중력 (위, 아래)은 가로 LinearLayout에서 작동합니다.

+0

안녕하세요! 그래도 방향 속성은 어떤 역할을합니까? 내가 '세로'에서 '가로'로 갈 때 레이아웃에 어떤 변화도 없었습니다 ... 고마워요! –

1

그냥, 내 경우 (기초 단지 exemple에 :)

작품 잘 트릭을 할해야

중력 = 수평 선형 레이아웃에 "오른쪽"

를 넣어 귀하의 레이아웃에) :

<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" > 

    <!-- VIDEO BUTTON CONTAINER --> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:background="#000000" 
      android:gravity="right"> 

     <!-- VIDEO BUTTON --> 
     <ImageButton 
       android:id="@+id/button_video" 
       android:layout_width="30dp" 
       android:layout_height="30dp" 
       android:layout_margin="10dp" 
       android:background="@android:color/background_light"/> 
    </LinearLayout> 

    <!-- some FrameLayout and another LinearLayout --> 
</LinearLayout> 

- 편집 -

LinearLayout의 방향 : 수직 및 수평선을 사용하면 레이아웃 내부의 자식을 가로 또는 세로로 나란히 배치 할 방법을 정의 할 수 있습니다.

중력 속성을 사용하면 레이아웃의 오른쪽에있는 레이아웃의 앵커를 제어 할 수 있습니다.

+0

'View' 내부의 내용을 조정합니다 ... 부모 내부의'View'가 아닙니다. – codeMagic

관련 문제