4
我曾经有一个简单的main.xml中的布局,只有2通过ViewFlipper包装翻转的看法。它的工作(仍然有效)很大,使用下面的代码:如何正确使用充气嵌套ViewFlipper布局?
setContentView(R.layout.main);
mTV1 = (TextView) findViewById(R.id.textview01);
mTV2 = (TextView) findViewById(R.id.textview02);
mViewFlipper = (ViewFlipper)findViewById(R.id.flipper01);
我现在想添加2个按钮上的独到见解顶部,在类似的方式来this:
<LinearLayout
android:id="@+id/linearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/linearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/button01" android:layout_height="wrap_content" android:text="Button 1" android:layout_width="0dip" android:layout_weight="1"></Button>
<Button android:id="@+id/button02" android:layout_height="wrap_content" android:text="Button 2" android:layout_width="0dip" android:layout_weight="1"></Button>
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout01"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ViewFlipper
android:id="@+id/flipper01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
/>
<TextView
android:id="@+id/textview02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text2"
/>
</ViewFlipper>
</RelativeLayout>
</LinearLayout>
我的问题是我直观地通过插入findViewById的复合布局修改了原来的代码:
setContentView(R.layout.main);
mCompositeLayout = (LinearLayout) findViewById(R.id.linearLayout02);
mTV1 = (TextView) findViewById(R.id.textview01);
mTV2 = (TextView) findViewById(R.id.textview02);
mViewFlipper = (ViewFlipper)findViewById(R.id.flipper01);
但它展示了和以前一样!就好像我从未添加包含按钮的额外linearLayout02。
我错过了什么?我究竟做错了什么?
感谢。我做了无数次的“项目>清洁”,所以不是这样。但是......我才发现,原来我错了在'Android的按钮,而不是''wrap_content' fill_parent':layout_height'。由于一个愚蠢的错字而失去了许多小时...... – scatmoi 2013-04-19 02:54:26