【问题标题】:Android: Help with two linear layout that overlaps each other!Android:帮助两个相互重叠的线性布局!
【发布时间】:2011-07-21 12:38:12
【问题描述】:

我想在第三个父布局中有两个线性布局。我希望第一个线性布局方向是水平的,第二个是垂直的。

我尝试通过以下代码来实现这一点。但是,第二个线性布局没有出现。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#FFFFFF">
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:gravity="center_horizontal"
  >
<ImageButton android:id="@+id/ImageButton01"
android:layout_width="80px" 
android:layout_height="80px"
android:background="@drawable/projects_badge"
android:layout_margin="10px"/>
</LinearLayout>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:gravity="center_horizontal"
  >
<ImageView android:id="@+id/ImageView01"
    android:layout_width="200px" 
    android:layout_height="81px" 
    android:src="@drawable/logo"
    android:adjustViewBounds="true"
    android:layout_marginTop="15px"/>
<TextView android:id="@+id/TextView01"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:textColor="#9CC721"/>
</LinearLayout>
</LinearLayout>

我们将不胜感激。

提前致谢。

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    我认为您还需要在父布局中指定 android:orientation 属性。

    提示:

    dpdip 比 px 更受欢迎。

    更新:

    你的父布局应该是这样的:

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#FFFFFF"
    android:orientation="vertical">
    

    您在第二个子布局中的图像视图应如下所示:

    <ImageView android:id="@+id/ImageView01"
        android:layout_width="200px" 
        android:layout_height="81px" 
        android:src="@drawable/logo"
        android:adjustViewBounds="true"
        android:layout_marginTop="15px"
     android:scaleType="center"/>
    

    【讨论】:

    • 您不必为 LinearLayout 指定 android:orientation。如果没有提及,则默认为水平。 (尽管如果你把它写下来,它会增加代码的可读性)
    • @alextsc yathanx 让我知道,我不知道,因为我在 android 上工作了 1.5 年。但是由于他的布局是重叠的,我假设他想要垂直方向的布局。
    • 是的,这可能是真的。老实说,我只是跳过了这个问题,并且由于您的答案似乎正确,因此没有详细说明。所以我基本上只是看到“我认为你需要指定方向”并想清楚你不必这样做。 :)
    • @alextsc 是的,没关系,有时会发生。 :)
    • 非常感谢 Paresh Mayani。 :D:D:D 如果你也能帮我解决这个问题,我将不胜感激stackoverflow.com/questions/6775077/… 它更复杂:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2011-09-25
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多