Android布局中的层
我有一个带有背景图像的屏幕,底部有两个按钮。我使用的代码与此类似:Android布局中的层,android,android-layout,Android,Android Layout,我有一个带有背景图像的屏幕,底部有两个按钮。我使用的代码与此类似: <?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:orienta
<?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:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="0dip" android:layout_weight="1"
android:orientation="vertical" android:background="@drawable/mainbg">
</LinearLayout>
<ImageButton android:layout_height="wrap_content"
android:background="#FF000000" android:src="@drawable/button1"
android:padding="5dp"
android:id="@+id/ImageButton1" android:layout_width="fill_parent">
</ImageButton>
<ImageButton android:src="@drawable/button2" android:background="#FF000000" android:id="@+id/ImageButton2"
android:layout_width="fill_parent" android:focusable="true" android:saveEnabled="false" android:layout_height="wrap_content">
</ImageButton>
<TextView android:text="mywebsite.com" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
在这段代码中,背景屏幕被粉碎,以适应Botton没有使用的剩余屏幕空间。换句话说,两个按钮消耗了20%的屏幕空间,然后图像被粉碎成了剩余的80%
我的问题:
有没有一种方法可以产生某种分层效果,使我的按钮位于背景图像上方的一层上 我认为这很简单。您可以设置作为主布局的父布局的背景图像。因此,主要布局是有背景图像,而其他布局没有背景图像
android:layout_height="0dip"
因此,这将只占用图像高度的高度。所以你也需要在这方面下功夫。我不确定我是否理解你的问题。但这张图片“manbg”似乎是这些按钮的兄弟。如果希望它成为整个视图的背景,则应使该图像成为父线性布局的可绘制图像 我想这会满足你的要求:
<?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:orientation="vertical" android:background="@drawable/mainbg">
<ImageButton android:layout_height="wrap_content"
android:background="#FF000000" android:src="@drawable/button1"
android:padding="5dp"
android:id="@+id/ImageButton1" android:layout_width="fill_parent">
</ImageButton>
<ImageButton android:src="@drawable/button2" android:background="#FF000000" android:id="@+id/ImageButton2"
android:layout_width="fill_parent" android:focusable="true" android:saveEnabled="false" android:layout_height="wrap_content">
</ImageButton>
<TextView android:text="mywebsite.com" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<RelativeLayout
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/round_red">
<LinearLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/button1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_weight="1">
</ImageButton>
<ImageButton
android:id="@+id/button2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_weight="1">
</ImageButton>
</LinearLayout>
</RelativeLayout>
顺便说一句,你是如何设计你的用户界面的。Netbeans有一个非常灵活的UI。这将使这些问题变得微不足道
希望这能有所帮助。使用
相对设置,然后使用android:background
设置背景
现在,要将按钮放在底部,请使用线性布局
并在同一部分内使用两个图像按钮。在两个按钮上都提到android:width=“0dp”
和android:layout\u weight=“1dp”
您想要的确切XML布局:
<?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:orientation="vertical" android:background="@drawable/mainbg">
<ImageButton android:layout_height="wrap_content"
android:background="#FF000000" android:src="@drawable/button1"
android:padding="5dp"
android:id="@+id/ImageButton1" android:layout_width="fill_parent">
</ImageButton>
<ImageButton android:src="@drawable/button2" android:background="#FF000000" android:id="@+id/ImageButton2"
android:layout_width="fill_parent" android:focusable="true" android:saveEnabled="false" android:layout_height="wrap_content">
</ImageButton>
<TextView android:text="mywebsite.com" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<RelativeLayout
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/round_red">
<LinearLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/button1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_weight="1">
</ImageButton>
<ImageButton
android:id="@+id/button2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_weight="1">
</ImageButton>
</LinearLayout>
</RelativeLayout>
更新:
为什么我建议使用RelativeLayout?
我建议您使用RelativeLayout,因为您可以根据父视图/子视图的相对位置调整和显示视图。如果您足够自信,那么在android中使用RelativeLayout
设计UI时,您就不必使用更多的子布局,也许
比
更适合您的设计
<?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:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="@drawable/mainbg" >
<ImageButton
android:id="@+id/ImageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button1"
android:layout_above="@id/ImageButton2"
android:layout_centerHorizontal="true" >
</ImageButton>
<ImageButton
android:id="@+id/ImageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button2"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true" >
</ImageButton>
</RelativeLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mywebsite.com" >
</TextView>
</LinearLayout>
我将尝试Netbeans。我有一些非常好的应用程序。但是我的用户界面需要帮助!这是免费软件吗?是的,它是免费的。我相信您将需要进行一些配置,以使其能够与android sdk一起工作。但我记得这并不难。祝你好运我想我试过了。如果我将图像放在背景中,我的按钮将移动到屏幕顶部。检查主容器,即主布局包含名称空间“xmlns”标记,并且包含其中的所有视图,因此最好在此布局中设置背景,以获得可绘制图像的全屏背景。