【问题标题】:Is there a way to make text, buttons, progress bar stay in around the same area with any resolution有没有办法让文本、按钮、进度条以任何分辨率保持在同一区域附近
【发布时间】:2013-05-29 22:16:04
【问题描述】:

有没有办法让文本、按钮、进度条以任何分辨率保持在同一区域附近。因此,如果您在 nexus 10 和 nexus 7 上,文本、按钮、进度条会显示在同一个地方。因为我的应用在 nexus 10 上看起来很傻。这是我的 xml 代码:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Next"
    android:textSize="20dp" 
    android:layout_marginTop="40dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:gravity="center"
    android:textStyle="bold"
    android:textColor="#FFFFFF"/>

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="150dp"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp" />

<ImageButton
    android:id="@+id/pauseicon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/pauseicon" 
    android:layout_gravity="center"
    android:layout_marginTop="20dp"
    style="?android:attr/borderlessButtonStyle"/>

【问题讨论】:

    标签: android android-layout textview imagebutton android-xml


    【解决方案1】:

    我不建议您像以前那样编写布局。为了使您的应用在不同设备上看起来相似,您应该对齐所有视图,以便它们相互关联。

    信息量很大here

    我还建议您使用 relative layout 而不是线性布局,因为更容易使视图相互关联,这(通常)使您的应用在不同的屏幕尺寸下看起来更好。

    这是一个相对布局的示例(来自开发文档)

    <EditText
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/reminder" />
    <Spinner
        android:id="@+id/dates"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/times" />
    <Spinner
        android:id="@id/times"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:layout_alignParentRight="true" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/times"
        android:layout_alignParentRight="true"
        android:text="@string/done" />
    

    【讨论】:

    • 你能举个例子吗?
    • @user2407147 - 完成 - 您应该更改布局以包含更多 alignParent.... 和 toLeft/RightOf.... 这有点烦人,意味着您不能总是像您一样设计布局想要它们,但要支持多种屏幕尺寸,这是必要的
    猜你喜欢
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多