简体   繁体   English

TextView未显示在对话框中

[英]TextView not displaying in Dialog

I am having a timer where i want to add time to the timer with from a dialog with NumberPickers. 我有一个计时器,我想从带有NumberPickers的对话框中向计时器添加时间。 This part is working fine, but then i add TextViews on top of the pickers, just for user friendliness, but the TextViews are not displaying. 这部分工作正常,但是为了方便用户使用,我在选择器的顶部添加了TextViews,但未显示TextViews。 What am i doing wrong? 我究竟做错了什么? This is my XML code. 这是我的XML代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<RelativeLayout
    android:id="@+id/rlHour"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/rlMin"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvNpHours"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/npHours"
        android:text="@string/hours" />

    <NumberPicker
        android:id="@+id/npHours"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/rlMin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvNpMinutes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/npMinutes"
        android:text="@string/minutes" />

    <NumberPicker
        android:id="@+id/npMinutes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/rlSec"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/rlMin"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvNpSeconds"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/npSeconds"
        android:text="@string/seconds" />

    <NumberPicker
        android:id="@+id/npSeconds"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

</RelativeLayout>

And this is how i make the dialog: 这就是我制作对话框的方式:

AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = LayoutInflater.from(context);
View dialogView = (inflater.inflate(R.layout.dialog, null));
final NumberPicker npHours = (NumberPicker) dialogView
                        .findViewById(R.id.npHours);
final NumberPicker npMinutes = (NumberPicker) dialogView
                        .findViewById(R.id.npMinutes);
final NumberPicker npSeconds = (NumberPicker) dialogView
                        .findViewById(R.id.npSeconds);
// Removed code for values of numberpickers
builder.setView(dialogView);
// Removed code for negative and positive buttons
AlertDialog dialog = builder.create();
dialog.show();

Since your NumberPickers have no layout position relationships, they are put at the top of the parent. 由于您的NumberPickers没有布局位置关系,因此它们被放置在父级的顶部。 Then, you are setting your text views above them, so they are offscreen. 然后,您将文本视图设置在它们上方,因此它们不在屏幕上。

Change the NumberPickers to layout_below the TextViews. 将NumberPickers更改为TextViews下方的layout_。

<TextView
    android:id="@+id/tvNpMinutes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/minutes" />

<NumberPicker
    android:id="@+id/npMinutes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvNpMinutes" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM