[英]Android ImageButton in different screens
In the UI for my application I have 5 ImageButton
all is ok on the 3.7" screen but if I have a screen of 2.7", 3.0" or other my UI will not scale and it looks bad. It looks like this: 在我的应用程序的UI中,我有5个
ImageButton
在3.7“屏幕上都可以,但是如果我有2.7”,3.0“或其他屏幕,我的UI将无法缩放并且看起来很糟糕。看起来像这样:
3,7" 3,7英寸
2,7" 2,7“
How do I make all have a nice look on all screens, just like on the screen 3.7"? 如何在所有屏幕上都拥有漂亮的外观,就像在3.7“屏幕上一样?
Code: main.xml 程式码:main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/two"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:orientation="vertical"
android:scaleType="fitXY" >
<ImageButton
android:id="@+id/ibTest1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/one" />
</LinearLayout>
</RelativeLayout>
Use a RelativeLayout
, and then place a LinearLayout
with height wrap_content
and put the buttons inside that LinearLayout. 使用
RelativeLayout
,然后放置一个高度为wrap_content
的LinearLayout
并将按钮放在该LinearLayout内。 Also use dp
instead of px
for sizes. 还要使用
dp
而不是px
作为尺寸。
PS If you post the code of your layout, we can help you better. PS:如果您发布布局代码,我们可以为您提供更好的帮助。
EDITED: Now that I can see your code I can show you want I meant with my answer: 编辑:现在,我可以看到您的代码,可以向您展示我想要的意思:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/two"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:gravity="center"
android:layout_centerInParent="true" >
<ImageButton
android:id="@+id/ibTest1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/one" />
<ImageButton
android:id="@+id/ibTest5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/one" />
</LinearLayout>
</RelativeLayout>
Can you provide some code? 你能提供一些代码吗? Maybe try add to in xml
也许尝试添加到XML
android:scaleType="fitXY"
First make image for all 首先为所有人制作图像
mdpi,hdpi,ldpi
mdpi,hdpi,ldpi
as per their size. 根据他们的大小。
take Lineatlayout in center for Buttons only. 仅将Buttonat置于Lineatlayout的中心。
then set property gravity="Center" ; 然后设置属性gravity =“ Center”;
确保您使用的是dp
不是使用'px'
这是一个常见原因。
try this add in each imageview in xml 尝试在xml中的每个imageview中添加
android:adjustViewBounds="true"
android:scaleType="centerCrop"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.