更改imagebutton在android上按比例调整设备大小(change imagebutton Proportional to size device on android)

编程入门 行业动态 更新时间:2024-10-22 08:19:11
更改imagebutton在android上按比例调整设备大小(change imagebutton Proportional to size device on android)

我正在使用一些图像按钮开发xml,图像按钮在模拟器中正确显示但它在Disorganization上

设备(例如galaxy fit)

如模拟器中所述https://www.dropbox.com/s/qeecp868ht61sck/emulator.jpg和galaxy fit https://www.dropbox.com/s/23r9tvtp0tcn7bs/fit.jpg

什么改变imagebutton与尺寸设备成比例?

我能做什么?

这是我的xml:

<RelativeLayout 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=".Main" android:background="@drawable/backmain" > <ImageButton android:id="@+id/btnfehrest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="53dp" android:background="@null" android:src="@drawable/fehrest" /> <ImageButton android:id="@+id/btndarbareh" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/btnfehrest" android:layout_marginLeft="21dp" android:background="@null" android:src="@drawable/darbareh" /> <ImageButton android:id="@+id/btnmahsulat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@+id/btndarbareh" android:layout_marginRight="17dp" android:background="@null" android:src="@drawable/mahsulat" /> <ImageButton android:id="@+id/btnkhoruj" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btndarbareh" android:layout_centerHorizontal="true" android:background="@null" android:src="@drawable/khoruj" /> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/main" android:scaleType="fitXY" /> </FrameLayout> </RelativeLayout>

I am develop xml with some image button,image buttons show properly in emulator but it Disorganization on

devices(for example galaxy fit)

As described in emulator https://www.dropbox.com/s/qeecp868ht61sck/emulator.jpg and galaxy fit https://www.dropbox.com/s/23r9tvtp0tcn7bs/fit.jpg

what change imagebutton Proportional to size device?

what can i do?

this is my xml:

<RelativeLayout 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=".Main" android:background="@drawable/backmain" > <ImageButton android:id="@+id/btnfehrest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="53dp" android:background="@null" android:src="@drawable/fehrest" /> <ImageButton android:id="@+id/btndarbareh" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/btnfehrest" android:layout_marginLeft="21dp" android:background="@null" android:src="@drawable/darbareh" /> <ImageButton android:id="@+id/btnmahsulat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@+id/btndarbareh" android:layout_marginRight="17dp" android:background="@null" android:src="@drawable/mahsulat" /> <ImageButton android:id="@+id/btnkhoruj" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btndarbareh" android:layout_centerHorizontal="true" android:background="@null" android:src="@drawable/khoruj" /> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/main" android:scaleType="fitXY" /> </FrameLayout> </RelativeLayout>

最满意答案

这完全是因为您在xml中使用了相对布局

相对布局始终与父视图或子视图保持xml中其他视图的关系。

所以在小屏幕上你的FrameLayout按钮图像试图适应屏幕,因为它保持与其他视图的关系,这就是它重叠的原因。

谈论对此提出建议

1)您可以使用滚动视图使用线性布局 ,即如果视图超出屏幕,您可以通过向下滚动查看它们。

//如果你不想这样做

2)您可以在layout-small中创建另一个具有相同名称的xml。 例:

res> layout> main.xml

res> layout-small> main.xml

第二个选项将帮助您为不同的屏幕尺寸创建多种支持。

注意:默认布局 - 小文件夹不存在但您可以创建它。

It is all because you are using Relative Layout in your xml

Relative layout always maintains a relationship with other views in your xml either with Parent view or with child views.

so on small screen your FrameLayout with button image trying to fit in the screen as it maintaining the relationship with other views, that's why its overlaping.

Talking about giving the suggestion regarding this.

1) You can use Linear Layout with scroll view, ie if views gets out of screen you can see them by scrolling down.

//If you don't wanna do this

2) You can create another xml in layout-small with same name. Example:

res> layout> main.xml

and

res> layout-small> main.xml

Second option will help you in creating multi support for different screen sizes.

Note: By Default layout-small folder is not present but you can create it.

更多推荐

本文发布于:2023-08-07 02:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458527.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上按   比例   大小   设备   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!