使用XML的java Android UI(Android和XML)
我正在创建一个如下图所示的用户界面
这就是它的外观:(使用Nexsus 5从我的应用程序中截图):
这是Nexsus S设备(4英寸)上的外观:
有人知道为什么会出现这种差异吗?这是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="#2e2e2e"
tools:context=".MainActivity"
安卓:id="@+id/viewew">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:weightSum="9"
安卓:orientation="vertical">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="horizontal"
安卓:layout_marginBottom="0dp"
安卓:layout_weight="8"
安卓:gravity="center_vertical"
>
<View
安卓:layout_width="0px"
安卓:layout_height="match_parent"
安卓:layout_weight="15" />
<Button
安卓:id="@+id/www"
安卓:layout_weight="2"
安卓:layout_width="90dp"
安卓:layout_height="90dp"
安卓:background="@drawable/www"
安卓:paddingLeft="10dp"
安卓:paddingRight="10dp"
/>
<View
安卓:layout_width="0px"
安卓:layout_height="match_parent"
安卓:layout_weight="15" />
<Button
安卓:id="@+id/www"
安卓:layout_weight="2"
安卓:layout_width="90dp"
安卓:layout_height="90dp"
安卓:background="@drawable/www"
安卓:paddingLeft="10dp"
安卓:paddingRight="10dp"
/>
<View
安卓:layout_width="0px"
安卓:layout_height="match_parent"
安卓:layout_weight="15" />
<Button
安卓:id="@+id/www"
安卓:layout_weight="2"
安卓:layout_width="90dp"
安卓:layout_height="90dp"
安卓:paddingLeft="10dp"
安卓:paddingRight="10dp"
安卓:background="@drawable/www"
/>
<View
安卓:layout_width="0px"
安卓:layout_height="match_parent"
安卓:layout_weight="15" />
</LinearLayout>
<View
安卓:id="@+id/idd"
安卓:layout_width="match_parent"
安卓:layout_height="400dp"
安卓:layout_alignParentBottom="true"
安卓:layout_weight="2"/>
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_weight="2"
安卓:layout_centerHorizontal="true"
安卓:text="Doesn't belong here?"
安卓:layout_alignParentBottom="true"
/>
</LinearLayout>
<include layout="@layout/buttons" />
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_weight="2"
安卓:layout_centerHorizontal="true"
安卓:text=" here?"
安卓:paddingBottom="15dp"
安卓:layout_alignParentBottom="true"
安卓:textColor="#f7f7f7"
安卓:id="@+id/tDoesntBelongHere"
/>
<com.lorentzos.flingswipe.SwipeFlingAdapterView
安卓:id="@+id/frame"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
app:rotation_degrees="15.5"
安卓:layout_above="@+id/eee"
tools:context=".MyActivity" />
</RelativeLayout>
# 1 楼答案
在android studio上,您必须为不同的设备设置屏幕大小
您的按钮有:
android:layout_width="90dp" android:layout_height="90dp"
因此,无论您使用哪个屏幕,其大小都将始终为90dp
在android studio中,您可以为同一页面创建更多xml页面:一个用于纵向、横向、ecc ecc,还有一个用于xxl ecc小屏幕
看看android开发者网站上的this链接
希望有帮助:)
编辑:
目前,我正在使用的电脑中没有Android studio,所以我试图解释一个可能的解决方案
设置边距而不是设置高度和宽度: 您可以从botside锚定所有内容,添加TextView
android:layout_alignParentBottom="true"
(如果需要,还可以添加一个边距底部)。然后像现在一样保持视图的静态高度为400dp,然后通过android:layout_above="@id/TextViewId
将其锚定到TextView的顶部(它没有id,请添加)现在,您必须对线性布局执行相同的操作:使用
android:layout_above="@id/idd
并删除静态大小。此时,您可以让按钮将height
设置为等于LinearLayout的height
(当然,您可以在按钮中设置margin
顶部机器人)对不起,如果我的英语不是很好,我希望你得到解决办法