0

我在绘制嵌套的线性布局时遇到问题。在第二个线性布局(第一个包含在主线性布局中)之后,没有其他任何显示!但我的 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>
4

5 回答 5

0

也许,在您的帮助下,我找到了解决问题的方法。在 xml 文件中,我将 android:orientation 设置为“垂直”,然后setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);在我的主要活动类中使我的应用程序“水平”。这是解决我的问题的正确方法吗?

于 2013-01-02T12:49:17.927 回答
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" 
    >
于 2013-01-02T11:56:24.337 回答
0

设置这个,

android:layout_width="wrap_content"
android:layout_weight="1"

把你的第一个和第二个包括在内linearLayout

谢谢。

于 2013-01-02T12:00:23.720 回答
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" 
于 2013-01-02T12:05:50.510 回答
0

也许,在您的帮助下,我找到了解决问题的方法。在 xml 文件中,我将 android:orientation 设置为“垂直”,然后setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);在我的主要活动类中使我的应用程序“水平”。这是解决我的问题的正确方法吗?

于 2013-01-02T12:46:10.347 回答