设计布局显示不一样
问题描述:
如何编辑xml文件布局。所有的显示屏幕都是一样的。设计布局显示不一样
屏幕尺寸4.7“,5.0”的显示精度。但除此之外的屏幕。显示失真。除了平板电脑。
帮我修复它。
screen_main.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"
tools:context="jp.vertice.test.MainScreenFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#51c8fc">
<ImageView
android:layout_width="200dp"
android:layout_height="195dp"
android:id="@+id/imageView2"
android:src="@mipmap/ic_launcher"
android:background="#fc0c0c"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn1"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/btn3"
android:layout_alignStart="@+id/btn3" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn2"
android:layout_below="@+id/btn1"
android:layout_alignLeft="@+id/btn1"
android:layout_alignStart="@+id/btn1" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn5"
android:layout_below="@+id/btn2"
android:layout_alignLeft="@+id/imageView2"
android:layout_alignStart="@+id/imageView2"
android:layout_marginTop="5dp" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn4"
android:layout_alignTop="@+id/btn5"
android:layout_toRightOf="@+id/btn5"
android:layout_toEndOf="@+id/btn5"
android:layout_marginLeft="9dp"
android:layout_marginStart="9dp" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn3"
android:layout_alignTop="@+id/btn4"
android:layout_toRightOf="@+id/btn4"
android:layout_toEndOf="@+id/btn4"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="205dp"
android:background="#F4F4F4"
android:layout_gravity="bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="YYYY.MM.DD"
android:id="@+id/txt1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="22dp"
android:layout_marginStart="22dp"
android:layout_marginBottom="173dp" />
<TextView
android:layout_width="230dp"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
android:id="@+id/text2"
android:layout_alignTop="@+id/txt1"
android:layout_alignLeft="@+id/txt1"
android:layout_alignStart="@+id/txt1"
android:layout_marginTop="25dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BUTTON"
android:id="@+id/btn6"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_alignTop="@+id/text2"
android:layout_toRightOf="@+id/text2"
android:layout_toEndOf="@+id/text2" />
<TextView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="FOOTER"
android:id="@+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="10sp"
android:textStyle="bold"
android:textAlignment="center"
android:gravity="center_vertical"
android:background="#FFFFFF" />
</RelativeLayout>
</FrameLayout>
答
您可以尝试使用一个网格布局。这样,图像列将填满整个屏幕。
答
你不能与DP工作,并期望在不同 相同的结果,如果你想同一个显示所有你可以用weightSum
和weight
这里工作的设备是一个小例子
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
答
不要这里使用Frame Layout,因为Frame Layout用于显示单个视图。
答
我看你使用的固定dp值为layout_width
和layout_height
。 dp
表示密度独立像素。它不是一个尺寸独立的像素。 dp
确保您的布局在具有相同尺寸但不同像素密度的设备上看起来相同。在较大的设备上它看起来不一样。 如果你想扩展到更大的设备,你将不得不使用match_parent
和wrap_content
。 使用相对布局的强大功能也可以将项目放置在屏幕的右侧。
您还可以为不同大小的设备制作单独的布局文件。所以你可以根据大小来定制它。 您可以通过创建一个名为layout-sw600dp/
(或任何您想要的数字)的新布局文件夹来执行此操作,该文件夹仅用于至少具有指定宽度的设备(本例中为600dp)。 确保您的布局文件在此文件夹中与普通文件夹中的名称相同。
你想看到的究竟是什么?我的意思是,什么是正确的?你的意思是4.7“的例子是你想要的每一个设备?你的意思是”尤其是“平板电脑? – miva2