【问题标题】:Expandable listview not fit to the whole fragment in android可扩展的列表视图不适合 android 中的整个片段
【发布时间】:2018-07-12 09:14:29
【问题描述】:

activity_Main.xml

<android.support.design.widget.BottomNavigationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_gravity="bottom"
    android:background="@android:color/white"
    app:elevation="8dp"
    app:menu="@menu/menu_navigation" />

</android.support.design.widget.CoordinatorLayout>

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.efftronics.android.mobilecashflow.Activity.MainActivity"
tools:showIn="@layout/activity_main">
<FrameLayout
    android:id="@+id/fragment_frame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" >
</FrameLayout>
</android.support.constraint.ConstraintLayout>

fragment_home.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/lin_fragment_home"
android:layout_height="match_parent">
    <ExpandableListView
        android:id="@+id/expandible_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:groupIndicator="@null">

    </ExpandableListView>
</android.support.constraint.ConstraintLayout>

在主要活动中,我设置了 activity_main.xml。在那个主布局中,我包含了 content_main.xml 在片段中,我需要设置 Expandablelistview。但它并没有设置为整个片段。它被设置为仅片段的中心。

请帮助我。我尝试了很多方法。但没有得到解决方案。

任何帮助将不胜感激。

谢谢。

【问题讨论】:

  • 请告诉我需要更改哪个布局文件?@JaydeepPatel
  • 在您的 fragment_frame 布局中,您可以尝试将宽度和高度都设置为 0dp 吗?而不是 wrap_content

标签: android android-layout expandablelistview android-coordinatorlayout android-constraintlayout


【解决方案1】:

看起来你的框架布局@+id/fragment_frame 的高度和宽度是wrap_content,同时也被限制在所有边上。如果我猜的话,我会将高度和宽度设为match_parent 并确保约束具有绝对约束。

【讨论】:

  • match_parent 不应在 ConstraintLayout 内部使用(ConstraintL 的 GoogleDoc)
【解决方案2】:

我已将框架布局的宽度和高度更改为 0dp。然后我得到了整个片段的可扩展列表。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.efftronics.android.mobilecashflow.Activity.MainActivity"
tools:showIn="@layout/activity_main">

<FrameLayout
    android:id="@+id/fragment_frame"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.6"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</FrameLayout>

</android.support.constraint.ConstraintLayout>

【讨论】:

    猜你喜欢
    • 2017-05-19
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多