【问题标题】:My .xml files layout is not showing properly in simulation我的 .xml 文件布局在模拟中未正确显示
【发布时间】:2012-11-16 04:36:39
【问题描述】:

在这种情况下,我的 xml 文件显示了某种布局,而在运行时会生成另一个布局。对于为什么在运行时显示的布局与给定的布局完全不同,我感到非常困惑。这是xml文件的代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


        <EditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <Button
        android:id="@+id/signUp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Sign up!" />
</LinearLayout>

这会在标签和按钮上显示在此处插入名称。该按钮已正确绑定并按下它确实会执行某些操作,但是我无法在运行时输入文本字段。

【问题讨论】:

    标签: java android android-layout android-emulator


    【解决方案1】:

    这个看起来不错。仔细检查您是否正在使用您的 java 代码更改任何属性。

    【讨论】:

      【解决方案2】:

      尝试改用这个。我已经删除了无用的 LinearLayout 并尝试使 EditText 可点击。

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical" >
      
          <EditText
              android:id="@+id/username"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:clickable="true"
              android:ems="10" >
      
              <requestFocus />
          </EditText>
      
          <Button
              android:id="@+id/signUp"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Sign up!" />
      </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-29
        相关资源
        最近更新 更多