1
我遇到了修改的android布局的问题。在我扩展正常的相对布局后,它将自动调整大小,所有嵌入的其他视图将消失。在自定义RelativeLayout中丢失视图
<namespace.SquareRelativeLayout
android:layout_weight="1"
android:id="@+id/firstBtn"
android:background="#ff0000"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/firstBtnImage"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/firstBtnDrawable" />
<TextView
android:id="@+id/firstBtnLabel"
android:layout_alignParentBottom = "true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffff"
android:text="@string/firstBtnlabel"
android:textStyle="bold" />
</namespace.SquareRelativeLayout>
但是文本视图和图像视图没有显示,即使它们在屏幕上的任何位置。
我感谢每一个后面。
编辑:
namespace namespace
{
class SquareRelativeLayout : RelativeLayout
{
public SquareRelativeLayout (Context context, IAttributeSet attrs, int defStyle) : base (context, attrs, defStyle)
{
}
public SquareRelativeLayout (Context context, IAttributeSet attrs) : base (context, attrs)
{
}
public SquareRelativeLayout (Context context) : base (context)
{
}
protected override void OnMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
//Get canvas width
int w = MeasureSpec.GetSize (widthMeasureSpec);
base.SetMeasuredDimension (w, w);
}
}
}
请注意,我们应该看看您如何修改实现SquareRelativeLayout的RelativeLayout。 – fasteque