【问题标题】:Android fragment inflated from layout resource showing an extra strip at the top从布局资源膨胀的 Android 片段在顶部显示了一个额外的条带
【发布时间】:2016-10-25 18:28:39
【问题描述】:

我正在尝试创建 Internet 连接错误对话框。我有它的 dialogFragment 代码,它膨胀了一个布局。问题是,布局在android studio中看起来很好,但在手机上,它的顶部出现了一个额外的水平条。

这是布局代码:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
style="@style/Animation.AppCompat.Dialog">


<TextView
    android:text="TextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:layout_weight="1" />

<RadioButton
    android:text="RadioButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radioButton"
    android:layout_weight="1" />
</LinearLayout>

谁能帮我理解为什么我会得到这个额外的条带。我尝试放置 CardView 和其他布局而不是 LinearLayout,但条似乎超出了布局文件。我无法访问或修改它。

【问题讨论】:

  • @RishabhDuttSharma 这很有帮助。天哪,图书馆一开始可能会很痛苦。

标签: android android-layout android-fragments android-linearlayout android-cardview


【解决方案1】:

DialogFragment 顶部有一个默认分隔符。 您可以使用以下代码删除分隔线 -

int dividerID = dialog.getContext().getResources().getIdentifier("android:id/titleDivider", "id", "android"); 查看分隔符 = dialog.findViewById(dividerID); 然后,您可以将高度设置为 0 或将视图设置为透明色。

【讨论】:

    猜你喜欢
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 2021-06-26
    相关资源
    最近更新 更多