这是我的代码!!在这里,我添加了背景图像,我需要按钮、标签和文本字段显示在背景图像上方。我已经使用了框架布局,但我没有得到预期的结果!只有背景图像填满屏幕,但按钮和其他内容没有显示!我是 android 新手..请帮助!!!
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingRight="40dp" >
<TextView
android:id="@+id/tvname1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:text="your name"
android:textSize="20dp"
android:textStyle="italic" />
<EditText
android:id="@+id/etboyname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="boyname" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvname2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="your crushs name"
android:textSize="20dp"
android:textStyle="italic" >
</TextView>
<EditText
android:id="@+id/etgirlname"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:hint="girlname" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btclick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:background="@drawable/custom" />
<Button
android:id="@+id/btsamegender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:background="@drawable/gender2" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvsame1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_marginLeft="15dp"
android:text="opposite gender"
android:textSize="20dp"
android:textStyle="italic" />
<TextView
android:id="@+id/tvsame1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_marginLeft="15dp"
android:text="same gender"
android:textSize="20dp"
android:textStyle="italic" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/imageanim"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</FrameLayout>
最佳答案
您的 ImageView 占据了整个屏幕,因为它设置为“fill_parent”。它或多或少位于所有其他布局之上,因为您将其添加为最后一个 View ,这就是为什么您在运行应用程序时看不到它们。
尝试将 ImageView 移至顶级线性布局上方,看看这是否不能解决您的问题。
但是一般来说 - 要添加背景,请按照此问题的答案中的建议进行操作: how to add background image to activity?
编辑:
这就是我的建议 - 您的 XML 文件应该这样开始。
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageanim"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingRight="40dp" >
关于android - 框架布局中的嵌套线性布局不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22586001/