Android的按钮不结垢 [英] Android Buttons not scaling
问题描述
这似乎是一个非常基本的问题,但我似乎无法弄清楚。我做阅读就如何使Android扩展到大,小屏幕了不少。
我有一个专为平板电脑和那里的伟大工程的应用程序。然而,当我在移动(手机)版工作,我希望确保它至少会看OK,如果有人打开它在手机上。
大家除了扩展的按钮很大....我只是似乎无法得到的按钮来扩展。
他们上的Tab很好看......但在手机上,他们采取了整个屏幕。
感谢您的帮助。
下面是code:
main.xml中
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / main_landscape
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@绘制/ main_menu_plus_landscape
机器人:方向=垂直> <按钮
机器人:ID =@ + ID / button_list
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_marginRight =38dp
机器人:layout_marginTop =200dp
机器人:背景=@布局/ button_main_selector
机器人:填充=40dp
机器人:文字=@字符串/ main_start_list
机器人:文字颜色=@色/白
机器人:TEXTSIZE =30dp
机器人:字体=SANS/>
<按钮
机器人:ID =@ + ID / button_emulator
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_above =@ + ID / AdView的
机器人:layout_alignLeft =@ + ID / button_list
机器人:layout_alignRight =@ + ID / button_list
机器人:layout_marginBottom =168dp
机器人:背景=@布局/ button_main_selector
机器人:填充=40dp
机器人:文字=@字符串/ main_start_emulator
机器人:文字颜色=@色/白
机器人:TEXTSIZE =30dp
机器人:字体=SANS/>< / RelativeLayout的>
布局/ button_main_selector.xml
<?XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
<! - 巴顿聚焦 - >
<项目的android:state_focused =真
机器人:STATE_ pressed =假
机器人:可绘制=@绘制/ main_buttons_selected
/>
<! - 巴顿重点pressed - >
<项目的android:state_focused =真
机器人:STATE_ pressed =真
机器人:可绘制=@绘制/ main_buttons_selected
/>
<! - 巴顿pressed - >
<项目的android:state_focused =假
机器人:STATE_ pressed =真
机器人:可绘制=@绘制/ main_buttons_selected
/>
<! - 按钮默认图片 - >
<项目机器人:可绘制=@绘制/ main_buttons/>< /选择>
绘制 - 华电国际/ main_buttons.xml
<?XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:形状=矩形机器人:填充=10dp>
[固体机器人:颜色=#71bbe3/>
<角落
机器人:bottomRightRadius =10dp
机器人:bottomLeftRadius =10dp
机器人:topLeftRadius =10dp
机器人:topRightRadius =10dp/>
< /形状>
我也试图把我的按钮,将文件只是绘制,它似乎并没有帮助。有什么建议么? (注意:我的按键都只是纯色,无图像)
RES /绘制/ main_buttons.xmlRES /绘制/ main_buttons_selected.xmlRES /绘制/ button_main_selector.xml
我已经看到你的code,首先我会告诉你的,你应该张贴什么样的看法,你想有形象,谢胜利,THIG是你给了
的android:layout_marginRight =38dp
的android:layout_marginTop =200dp
在您的第一个按钮code,&安培;在谢胜利键U给利润率这样
的android:layout_marginBottom =168dp
和其他任何东西都取决于你想实现什么样的设计布局。
我给你的建议是永远不会从例如左向右AUR给direction.because缘特别是如果你给利润率从左边50像素比它看起来正常的设备正常,而在高分辨率的设备看起来不太好怎么一回事,因为它会采取50像素保证金使用这种语法的Android的任何决议device.instead:alignParentLeft = true并且总是用这样那样的语法乌尔相对layout.with里面的习惯ssuch语法您的元素将永远在你获得所需的位置..goto Android开发者网站,并检查是线性的,相对布局,什么是线性的,相对布局研究的不同属性之间的差别的所有属性,比如 FILL_PARENT
的意思, WRAP_CONTENT
&安培; match_parent
100%以上,你会得到solution.if您有任何疑问比我在这里<联接href=\"http://chat.stackoverflow.com/rooms/13436/smart-phones-developer\">http://chat.stackoverflow.com/rooms/13436/smart-phones-developer你可以问我您的问题here.and我会建议你来发表您的图片
谢谢
阿米尔·罕我。
This seems like a very basic question but I can't seem to figure it out. I have done quite a bit of reading on how to make android scalable to big and small screens.
I have an app that is designed for a tablet and works great on there. However, while I am working on the mobile(phone) version I want to ensure it will at least look "ok" if someone opens it on a phone.
Everyone scales great besides the buttons.... I just can't seem to get the buttons to scale.
They look great on the Tab...but on the phone, they take up the whole screen.
Thank you for the help.
Here is the code:
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_landscape"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main_menu_plus_landscape"
android:orientation="vertical" >
<Button
android:id="@+id/button_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="38dp"
android:layout_marginTop="200dp"
android:background="@layout/button_main_selector"
android:padding="40dp"
android:text="@string/main_start_list"
android:textColor="@color/white"
android:textSize="30dp"
android:typeface="sans"/>
<Button
android:id="@+id/button_emulator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/adview"
android:layout_alignLeft="@+id/button_list"
android:layout_alignRight="@+id/button_list"
android:layout_marginBottom="168dp"
android:background="@layout/button_main_selector"
android:padding="40dp"
android:text="@string/main_start_emulator"
android:textColor="@color/white"
android:textSize="30dp"
android:typeface="sans" />
</RelativeLayout>
layout/button_main_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Button Focused-->
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/main_buttons_selected"
/>
<!-- Button Focused Pressed-->
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/main_buttons_selected"
/>
<!-- Button Pressed-->
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/main_buttons_selected"
/>
<!-- Button Default Image-->
<item android:drawable="@drawable/main_buttons"/>
</selector>
drawable-hdpi/main_buttons.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#71bbe3"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
I have also tried putting my button files into just "drawable" and it does not seem to help. Any suggestions? (NOTE: my buttons are just solid color, no images)
res/drawable/main_buttons.xml
res/drawable/main_buttons_selected.xml
res/drawable/button_main_selector.xml
i have seen your code,first of all i will tell you,you should post image that what kind of view you want to have,secound thig is that you have given
android:layout_marginRight="38dp"
android:layout_marginTop="200dp"
in your first button code, & in your secound button u have given margin like this
android:layout_marginBottom="168dp"
and every thing else is depends on layout that what kind of design you want to implement.
my suggestion to you is never give margin specially from left aur right direction.because for example if you give margin from left to 50px than it looks ok in normal device,while not look well in high resolution devices beacuse it will take 50px in any resolution device.instead of margin use this kind of syntax android:alignParentLeft=true and always have a habit of using such kind of syntax inside ur relative layout.with ssuch syntaxes your elements will be always at the position in which you get desired..goto the android developer site and check what is a difference between linear and relative layout and what is different properties of linear and relative layout study all properties like a meaning of fill_parent
,wrap_content
& match_parent
than 100% you will get solution.if you have any query than join with me here http://chat.stackoverflow.com/rooms/13436/smart-phones-developer you can ask me your issue here.and i will suggest you to post your image
Thanks Aamirkhan I.
这篇关于Android的按钮不结垢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!