我在绘制嵌套的linearLayout时遇到问题。 在第二个linearLayout(第一个包含在主linearLayout中)之后,没有显示任何其他内容!但是我的xml文件中没有任何错误消息。
---main linearLayout--------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
tools:context=".MainActivity"
>
------first included linearLayout: it's shown without nay problems--------------------
<LinearLayout
android:background="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="@string/hello_world" />
</LinearLayout>
------second included linearLayout: it's NOT shown--------------------
<LinearLayout
android:background="#CCCCCC"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:gravity="center"
android:weightSum="1">
<ImageView
android:layout_width="0dp"
android:layout_weight="0.3"
android:layout_marginLeft="2dp"
android:background="@drawable/ic_launcher"
android:layout_height="100dp"/>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
布局顶部的更改
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
tools:context=".MainActivity"
>
对此:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity"
>
答案 1 :(得分:0)
设置此,
android:layout_width="wrap_content"
android:layout_weight="1"
到您的第一个和第二个linearLayout
。
感谢。
答案 2 :(得分:0)
将您的Linearlayout
方向android:orientation="vertical"
置于最佳位置。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" <---Change orientation. tools:context=".MainActivity"
答案 3 :(得分:0)
也许,在你的帮助下,我找到了解决问题的方法。
在xml文件中,我将android:orientation设置为“vertical”,然后在我的主活动类中使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
使我的应用程序“水平”。这是解决问题的正确方法吗?
答案 4 :(得分:0)
也许,在你的帮助下,我找到了解决问题的方法。在xml文件中,我将android:orientation设置为“vertical”,然后在我的主活动类中使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
使我的应用程序“水平”。这是解决问题的正确方法吗?