【问题标题】:Same XML - Different Layouts - API 10 and API 17相同的 XML - 不同的布局 - API 10 和 API 17
【发布时间】:2013-07-08 13:32:07
【问题描述】:

下面的 xml 会根据 API 生成两个不同的布局屏幕。此布局在具有 API 17 的设备中,布局看起来不错,输入文本集中在屏幕上。

但是在 API 10 上运行的相同布局看起来很奇怪,字段位于左上角...

xml代码sn-p如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#005500">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dip"
        android:layout_marginRight="15dip"
        android:layout_marginTop="200dip"
        android:orientation="vertical" >

        <EditText 
          android:id="@+id/et_nome_login"
          android:layout_width="match_parent"
          android:layout_height="40dip"
          android:paddingRight="15dip"
          android:paddingLeft="15dip"
          android:inputType="text"
          android:nextFocusDown="@+id/et_senha_login"
          android:background="@drawable/bg_login_name"/>

        <EditText 
          android:id="@+id/et_senha_login"
          android:layout_width="match_parent"
          android:layout_height="40dip"
          android:paddingRight="15dip"
          android:paddingLeft="15dip"
          android:inputType="textPassword"
          android:background="@drawable/bg_login_senha"/>

        <ImageButton 
            android:id="@+id/ib_login"
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:layout_marginTop="20dip"
            android:background="@drawable/btn_entrar"/>

    </LinearLayout>


    <FrameLayout
            android:id="@+id/progress_login"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#AA000000"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:visibility="gone" >

            <ProgressBar
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_gravity="center" />
    </FrameLayout>

</FrameLayout>   

在 API 10 上,视图放置在左上角,而在 API 17 上,字段被更正后放置在中心位置。问题出在哪里?

【问题讨论】:

    标签: android api android-layout android-xml


    【解决方案1】:

    你可以包含不同的xml:

    <include layout="@layout/include_file" />
    

    不同的xml必须在自己的同名API文件夹中:

    价值观-v11

    • include_file.xml
    • ...

    价值观-v14

    • include_file.xml
    • ...

    【讨论】:

    • 感谢您的帮助,但事实并非如此。或者我不明白......布局必须相同......我的问题是为什么 sabe xml 会根据 API 生成两个不同的屏幕......这个布局只包含自旧版本以来执行部分 android 的元素API 的版本......我无法理解这种差异......
    【解决方案2】:

    您应该使用 weight 属性来运行每个尺寸或 API 的一个 xml。

    试试这个link

    【讨论】:

    • Rumit 感谢您的回复。我尝试了许多使用重量的组合,但没有奏效。它具有相同的行为....
    猜你喜欢
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    相关资源
    最近更新 更多