【问题标题】:auto adjust the size and position of edittext and button自动调整edittext和按钮的大小和位置
【发布时间】:2011-03-08 04:39:20
【问题描述】:

在模拟器中,edittext 和按钮的大小看起来不错,但在摩托罗拉里程碑中,它们都太小了。我认为有不同类型的屏幕布局。是否可以自动调整大小?我的 xml 如下:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText android:id="@+id/txtToText_e" 
 android:layout_width="270px" 
 android:layout_height="wrap_content" 
 android:textSize="18sp" 
 android:hint="Type To Compose" 
 android:layout_alignParentBottom = "true"
 android:layout_alignParentLeft="true"/>   <Button android:text="Send" 
 android:id="@+id/btnDone_e" 
 android:layout_width="85px" 
 android:layout_height="wrap_content"      
 android:layout_alignParentBottom = "true"
 android:layout_alignParentRight="true"/>                                 

为了在将手机从纵向变为横向时自动调整大小的编辑文本,我在 AndroidManifest.xml 中添加了这些 xml 代码

    <supports-screens android:smallScreens="true"
              android:normalScreens="true"
              android:largeScreens="true"
              android:anyDensity="true" />

但没有任何改变=[。如何解决?

谢谢。

【问题讨论】:

    标签: android button android-edittext screen-orientation


    【解决方案1】:

    如果您希望根据屏幕密度更改尺寸,请使用dip 而非px 作为尺寸。

    【讨论】:

    • 现在我使用“dip”。将手机从纵向变为横向时,我希望此文本框大小根据屏幕宽度自动调整。纵向时它仍然是相同的尺寸。
    • @soclose:您可以使用维度资源 (res/values/dimens.xml) 指定宽度,并为横向 (res/values-land/dimens.xml) 设置不同的值。或者,为横向设置不同的布局 (res/layout-land/whatever.xml)。还有其他可能的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-07
    • 2019-11-20
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    相关资源
    最近更新 更多