为什么 TextView 不见了?
我以编程方式将文本设置为 TextView 和 EditText。但这些小部件不可见。如果我将 android:layout_marginTop="100dp" 作为 Textview,那么我就可以看到这些小部件。为什么会这样呢?你能建议我任何其他方式吗?提前致谢。
*<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/homepage_background">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_gravity="center"
android:layout_weight="1">
<LinearLayout android:layout_width="fill_parent"
android:layout_gravity="center" android:gravity="center"
android:orientation="vertical" android:layout_height="wrap_content">
<!-- This Textview is not visible -->
<TextView android:layout_width="fill_parent" android:id="@+id/updateText"
android:layout_height="wrap_content" android:textColor="@color/homepage_labelText"
android:layout_gravity="center" android:gravity="center"
/>
<!-- This EditText box also not visible (only half) -->
<EditText android:id="@+id/previousText" android:textColor="@color/homepage_labelText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:cursorVisible="false" android:layout_gravity="center"
android:layout_marginLeft="10dp" android:maxLines="2"
android:layout_marginRight="10dp" />
<TextView android:layout_width="fill_parent" android:id="@+id/text"
android:layout_height="wrap_content" android:textColor="@color/homepage_labelText" android:text="Complaint"
android:layout_gravity="center" android:gravity="center"
android:layout_marginTop="10dp" />
<EditText android:id="@+id/updateEditText" android:lines="5"
android:focusable="true" android:inputType="textMultiLine"
android:gravity="top" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:textSize="15dp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="Enter to update complaint info " />
</LinearLayout>
</ScrollView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="50dp"
android:gravity="center" android:background="@color/homepage_title_background"
android:layout_gravity="center">
<Button android:id="@+id/updateComplaintSubmitButton"
android:text=" Update " android:textColor="@color/homepage_labelText"
android:layout_width="wrap_content" android:layout_height="40dp" />
<Button android:id="@+id/updateComplaintCancelButton"
android:text=" Cancel " android:textColor="@color/homepage_labelText"
android:layout_marginLeft="30dp" android:layout_width="wrap_content"
android:layout_height="40dp" />
</LinearLayout>
</LinearLayout>*
I'am setting the text to TextView and EditText programmatically. but those widgets are not visible. If i take android:layout_marginTop="100dp" for Textview, then i'am able to see those widgets. Why so? Can you suggest me any other way. Thanks in advance.
*<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/homepage_background">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_gravity="center"
android:layout_weight="1">
<LinearLayout android:layout_width="fill_parent"
android:layout_gravity="center" android:gravity="center"
android:orientation="vertical" android:layout_height="wrap_content">
<!-- This Textview is not visible -->
<TextView android:layout_width="fill_parent" android:id="@+id/updateText"
android:layout_height="wrap_content" android:textColor="@color/homepage_labelText"
android:layout_gravity="center" android:gravity="center"
/>
<!-- This EditText box also not visible (only half) -->
<EditText android:id="@+id/previousText" android:textColor="@color/homepage_labelText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:cursorVisible="false" android:layout_gravity="center"
android:layout_marginLeft="10dp" android:maxLines="2"
android:layout_marginRight="10dp" />
<TextView android:layout_width="fill_parent" android:id="@+id/text"
android:layout_height="wrap_content" android:textColor="@color/homepage_labelText" android:text="Complaint"
android:layout_gravity="center" android:gravity="center"
android:layout_marginTop="10dp" />
<EditText android:id="@+id/updateEditText" android:lines="5"
android:focusable="true" android:inputType="textMultiLine"
android:gravity="top" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:textSize="15dp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="Enter to update complaint info " />
</LinearLayout>
</ScrollView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="50dp"
android:gravity="center" android:background="@color/homepage_title_background"
android:layout_gravity="center">
<Button android:id="@+id/updateComplaintSubmitButton"
android:text=" Update " android:textColor="@color/homepage_labelText"
android:layout_width="wrap_content" android:layout_height="40dp" />
<Button android:id="@+id/updateComplaintCancelButton"
android:text=" Cancel " android:textColor="@color/homepage_labelText"
android:layout_marginLeft="30dp" android:layout_width="wrap_content"
android:layout_height="40dp" />
</LinearLayout>
</LinearLayout>*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我有同样的问题,它来自你的 TextView 的重力属性..它设置为中心。我不确定为什么 android 在这种情况下隐藏 TextView,我也在尝试解决这个问题
I think I have the same problem and it comes from the gravity property of your TextView.. it is set to center. I don't know for sure why android is hiding the TextView in this case and I am trying to fix this as well