2014-10-05 75 views
0

我已经创建了一个自定义的线性布局,以便让“square”布局符合其父级的宽度,但我无法将其与另一个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

添加到您的LinearLayoutandroid:layout_below="@id/game_layout"