TextView 在应用程序中不可点击

TextView is unclickable in application

我正在设计一个弹出式 AlertDialog,它将警报对话框的视图设置为以下 XML 文件。由于某种原因,该文件不会添加边距,我无法弄清楚我做错了什么。边距和填充在 activity_priority_level_values LinearLayout、包含所有 TextView 的 LinearLayout 或任何 TextView 中不起作用。如何为对话框边框和所有文本视图之间的边距添加边距(或填充)?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_priority_level_values"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/large_space">
<TextView  android:id="@+id/level_1_header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/level_1_header"/>

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

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

<TextView  android:id="@+id/level_2_decription"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/mid_space"
    android:text="@string/level_2_description"/>

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

<TextView  android:id="@+id/level_3_decription"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/mid_space"
    android:text="@string/level_3_description"/>

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

<TextView  android:id="@+id/level_4_description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/mid_space"
    android:text="@string/level_4_description"/>

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

<TextView  android:id="@+id/level_5_decription"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/level_5_description"/>
</LinearLayout>
</LinearLayout>

Activity

LinearLayout hiddenLayout = (LinearLayout)findViewById(R.id.activity_priority_level_values);
AlertDialog.Builder builder = new AlertDialog.Builder(this);

if(hiddenLayout == null){
    LinearLayout myLayout = (LinearLayout)findViewById(R.id.activity_law_priority);
    View hiddenInfo = getLayoutInflater().inflate(R.layout.activity_priority_level_values, null);
    builder.setView(hiddenInfo);
}
builder.create();
builder.show();

问题是你的观点膨胀了。

LinearLayout myLayout = (LinearLayout)findViewById(R.id.activity_law_priority);
View hiddenInfo = getLayoutInflater().inflate(R.layout.activity_priority_level_values, null);

你永远不应该用 null 膨胀。而是将代码更改为:

LinearLayout myLayout = (LinearLayout)findViewById(R.id.activity_law_priority);
View hiddenInfo = getLayoutInflater().inflate(R.layout.activity_priority_level_values, myLayout, false);

如果您使用 null 进行膨胀,布局参数将被忽略。