我正在尝试开发一款看起来像我上个月所做的iOS的Android应用。有一个带有背景图像和三个按钮的视图。背景图像有一个标题部分和一个页脚部分,我需要三个按钮来保持这两个部分之间。这是iOS版本的截图,也是我的android活动所需的输出:
现在我现在作为活动的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/fondo_pantalla"> >
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button1"
android:drawableLeft="@drawable/actividades_izq"
android:text="Actividades" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:drawableLeft="@drawable/agenda_izq"
android:paddingTop="60dp"
android:text="Agenda" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button2"
android:drawableLeft="@drawable/suscribete_izq"
android:text="Recibir Información de Juventud" />
</RelativeLayout>
我希望所有设备上的布局在纵向模式下看起来相同或非常相似。
现在它看起来非常不同,具体取决于屏幕尺寸。
欢迎任何帮助。
答案 0 :(得分:1)
试试这个,让我知道结果。
<?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/fondo_pantalla"> >
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/button1"
android:drawableLeft="@drawable/actividades_izq"
android:text="Actividades"
layout_weight="1" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawableLeft="@drawable/agenda_izq"
android:paddingTop="60dp"
android:text="Agenda"
layout_weight="1"/>
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawableLeft="@drawable/suscribete_izq"
android:text="Recibir Información de Juventud"
layout_weight="1"/>
</LinearLayout>
答案 1 :(得分:1)
我认为使用带有重量的线性布局可以解决您的问题。试试这个。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="3"
android:background="@drawable/ic_action_search">
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_launcher"
android:text="Agenda" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_action_search"
android:text="Actividades" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawableLeft="@drawable/fail"
android:text="Recibir Información de Juventud" />
</LinearLayout>
答案 2 :(得分:1)
首先将button2置于:
android:layout_centerInParent="true"
和button1到:
android:above="@+id\button2"
这样至少它的中心位置可以更好地适应屏幕尺寸。
答案 3 :(得分:1)
我认为您的问题是尝试为所有屏幕尺寸和密度提供布局。这几乎是不可能的。但你可以做的是在你的res文件夹中创建单独的文件夹
layout-small
layout-medium
layout-large
等等。请仔细阅读本文,因为在您的预览中,您只需使用一种布局即可支持几乎所有屏幕尺寸和密度......
将自定义布局放入单独的布局文件夹中,以便为用户提供所需的体验。希望它有所帮助;)