我已经git一个自定义视图,我希望显示为GridLayout
单元格。但每个视图都是拉伸并填满整个屏幕,我不明白为什么。这是代码:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/fr.infral.android.test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="2" >
<fr.infral.widget.TileView
android:id="@+id/tileViewTest_default"
android:layout_row="0"
android:layout_column="0" />
<fr.infral.widget.TileView
android:id="@+id/tileViewTest_top"
android:layout_row="0"
android:layout_column="1"
app:primaryAction="@drawable/infral_logo__top"
app:primaryText="Infral logo's top" />
<fr.infral.widget.TileView
android:id="@+id/tileViewTest_bottom"
android:layout_row="1"
android:layout_column="0"
app:captionAlign="top"
app:primaryAction="@drawable/infral_logo__bottom"
app:primaryText="Infral logo's bottom"
app:secondaryAction="@drawable/launcher_icon"
app:secondaryText="What an image !" />
</GridLayout>
以下是我的自定义视图中重要内容的摘要:
public class TileView extends RelativeLayout {
{
inflate(getContext(), R.layout.tile_view, this);
}
public TileView(Context context) {
super(context);
}
public TileView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TileView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
膨胀的布局:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<ImageView
android:id="@+id/tile_primaryAction"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
<LinearLayout
android:id="@+id/tile_caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:weightSum="1"
android:layout_alignParentBottom="true" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:orientation="vertical" >
<TextView
android:id="@+id/tile_primaryText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:singleLine="true"
android:hint="Nocte Caelum" />
<TextView
android:id="@+id/tile_secondaryText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:singleLine="true"
android:hint="Lorem ipsum" />
</LinearLayout>
<ImageView
android:id="@+id/tile_secondaryAction"
android:layout_width="48dp"
android:layout_height="48dp"
android:clickable="true" />
</LinearLayout>
</merge>
因此,为了澄清:我想了解为什么单元格填满整个屏幕,以及如何修改它以便GridLayout
填充整个屏幕并在其子节点之间划分空间。