【问题标题】:TextView and EditText not rendering in Android layoutTextView 和 EditText 未在 Android 布局中呈现
【发布时间】:2016-05-10 20:20:49
【问题描述】:

我正在尝试创建一个简单的游戏,但我遇到了布局问题。下面是我的 Xml 代码,我没有任何错误,但是当我尝试运行它时(文本 view_bet 一和编辑文本投注二没有出现在模拟器中,它们都应该出现在模拟器的底部。任何感谢您的帮助。

XML 代码

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#CD853F"
   android:orientation="vertical" >

<ac.nott.Game
    android:id="@+id/game"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:paddingBottom="1000dp" />

<TextView
    android:id="@+id/stack1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:padding="10dp"
    android:text="@string/fiftey"
    android:textColor="#000000"
    android:textSize="50sp" />

<TextView
    android:id="@+id/stack2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="34dp"
    android:padding="10dp"
    android:text="@string/fiftey"
    android:textColor="#000000"
    android:textSize="50sp" />

<Button
    android:id="@+id/go"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="@string/button2_text"
    android:textColor="#000000" />

<TextView
    android:id="@+id/betOne"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/go"
    android:layout_alignLeft="@+id/stack2"
    android:layout_alignRight="@+id/stack2"
    android:background="#FFFFCC"
   android:text="@string/text4"
    android:textColor="#000000" />

<EditText
    android:id="@+id/betTwo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/betOne"
    android:layout_alignLeft="@+id/stack1"
    android:layout_alignTop="@+id/betOne"
    android:layout_toLeftOf="@+id/Info"
    android:background="#FFFFCC"
    android:inputType="text"
    android:textColor="#000000" />


<TextView
    android:id="@+id/Info"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/go"
    android:layout_marginBottom="36dp"
    android:layout_marginLeft="20dp"
    android:layout_toRightOf="@+id/stack1"
    android:textColor="#000000"
    android:textSize="20sp" />

【问题讨论】:

  • 用LinearLayout改变RelativeLayout
  • 谢谢@OussemaAroua 但现在它们都在渲染
  • 请让你的笔记更清楚
  • @OussemaAroua 非常感谢亲爱的,我刚刚为 textview 添加了 (android:layout_above),它起作用了。

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


【解决方案1】:

改变这两个。 android:layout_alignBottom 表示视图的底部将处于相同的加号,因此可能会重叠。你可能想要android:layout_above

<TextView
android:id="@+id/betOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/go"
android:layout_alignLeft="@+id/stack2"
android:layout_alignRight="@+id/stack2"
android:background="#FFFFCC"
android:text="@string/text4"
android:textColor="#000000" />

<EditText
android:id="@+id/betTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/betOne"
android:layout_alignLeft="@+id/stack1"
android:layout_alignTop="@+id/betOne"
android:layout_toLeftOf="@+id/Info"
android:background="#FFFFCC"
android:inputType="text"
android:textColor="#000000" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多