我已经为Button创建了自己的布局。 Normaly我这个创建一个视图:构建与allways相同的自定义视图布局
LayoutInflater inflater = LayoutInflater.from(getActivity());
myButton = inflater.inflate(R.layout.mybutton, null, false);
现在,我的想法是,MyButton类扩展查看和我没有写这些线对每个按钮。但是我怎样才能在myButton构造函数中引入这两行?我不能写:
public MyButton(Context c)
{
this = inflater.inflate(R.layout.mybutton, null, false);
}
如何建立具有八方通相同的布局自定义视图这样我就可以建立一个新的为myButton与预装的布局是这样的:
MyButton myButton = new MyButton();
这是布局我想使用myButton的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:orientation="vertical"
android:paddingBottom="@dimen/PaddingBottom"
android:paddingLeft="@dimen/PaddingHorizontal"
android:paddingRight="@dimen/PaddingHorizontal"
android:paddingTop="@dimen/PaddingTop" >
<TextView
android:id="@+id/Fach"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/MarginTop"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/Klasse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/MarginTop"
android:text="" />
<TextView
android:id="@+id/Raum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="" />
</LinearLayout>
解决方案对我来说很奇怪。您正在扩展视图组以创建视图。后来合并,你要求android删除这个吊坠视图组。不是一个好设计 – Anirudh 2013-05-05 10:42:49