android:活动为对话框:layout_height =“ wrap_content”但仍然全屏

时间:2019-08-07 17:13:11

标签: android android-linearlayout

这是问题的好标题吗?

我的问题是,我将活动用作对话框(而不是使用全屏活动),但是即使我使用layout_height="wrap_content",对话框stil也会使用整个屏幕。

也尝试过使用DialogFragment,结果相同。

.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorDeadBackground"
    android:orientation="vertical"
    android:weightSum="1">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.7"
>
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</RelativeLayout>

<LinearLayout
    android:id="@+id/button_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.3"
    android:orientation="horizontal"
    android:weightSum="1">

    <ImageButton
        android:id="@+id/setProfileButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:src="@drawable/outline_portrait_black_48" />

    <ImageButton
        android:id="@+id/deletePictureButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:src="@drawable/outline_delete_black_48" />
</LinearLayout>
</LinearLayout>

这里是AndroidManifest.xml:

 <activity
        android:name=".ShowPicturesActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@style/MyPictures" />

这里是styles.xml:

<style name="MyPictures" parent="@style/MyDialogTheme">
    <item name="android:windowFullscreen">false</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert" />

如何使topLinearLayout高度达到wrap_content?

1 个答案:

答案 0 :(得分:0)

您已经为回收器视图包装内容指定了固定高度,在这种情况下,由于适配器中的项增加,使用更好的使用约束布局并从顶部和底部绑定回收器视图约束并将高度设置为0dp时,它无法扩展 只需尝试在reyclerview上将自身的高度设置为wrap_content并使用

app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
tools:listitem="@layout/your_layout"
tools:itemCount="10"