2014-10-05 1 views
0

"사각형"레이아웃을 부모의 너비에 맞추기 위해 사용자 지정 선형 레이아웃을 만들었지 만 다른 LinearLayout에 배치하는 데 문제가 있습니다. 나는 LinearLayout 그냥 SquareLinearLayout 이하로 원하고 나는 (두 레이아웃 상단 정렬)이있어 ...customLinear 레이아웃 위치 지정 문제

enter image description here

내가 android:parentAlignBottom="true"android:gravity="bottom"을 시도했지만 아무것도 나를 위해 작동하지

여기 내 레이아웃 XML입니다 : 여기

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.dekajoo.rpg.MainActivity" > 

    <com.dekajoo.rpg.custom_layouts.SquareLinearLayout 
     android:id="@+id/game_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:background="#f00" /> 

    <android:LinearLayout 
     android:id="@+id/control_bar" 
     android:layout_width="match_parent" 
     android:layout_height="100dip" 
     android:background="#0f0" 
     android:gravity="center" 
     android:orientation="horizontal" /> 

</RelativeLayout> 

그리고 나의 SquareLinearLayout 클래스입니다 :

package com.dekajoo.rpg.custom_layouts; 

import android.content.Context; 
import android.util.AttributeSet; 
import android.widget.LinearLayout; 

public class SquareLinearLayout extends LinearLayout { 

    public SquareLinearLayout(Context context) { 
     super(context); 
    } 
    public SquareLinearLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 
    /*public SquareView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    }*/ 

    @Override 
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
     int width = MeasureSpec.getSize(widthMeasureSpec); 
     int height = MeasureSpec.getSize(heightMeasureSpec); 
     int size = width > height ? height : width; 
     setMeasuredDimension(size, size); 
    } 
} 

감사합니다,

답변

0

, 당신의 LinearLayout이 추가 android:layout_below="@id/game_layout"