Android 使用ListView折叠工具栏
当我折叠Android 使用ListView折叠工具栏,android,listview,layout,Android,Listview,Layout,当我折叠工具栏,列表视图的外观是一半。它看起来就像正方形。然而,我想看到所有这些。它应该向下延伸列表视图可能有问题。我怎样才能解决这个问题?另外, 若你们不明白,我在图片中附上了这个问题。你会很容易理解的! EDIT:实际上,ImageView通常较宽,但在这里似乎不正确,因为我折叠了它。当它已满时,ListView的方形外观类似于图像 我的XML: <android.support.design.widget.CoordinatorLayout xmlns:android="http:
工具栏
,列表视图
的外观是一半。它看起来就像正方形。然而,我想看到所有这些。它应该向下延伸<代码>列表视图可能有问题。我怎样才能解决这个问题?另外,
若你们不明白,我在图片中附上了这个问题。你会很容易理解的!
EDIT:实际上,ImageView
通常较宽,但在这里似乎不正确,因为我折叠了它。当它已满时,ListView
的方形外观类似于图像
我的XML:
<android.support.design.widget.CoordinatorLayout 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"
tools:context="com.example./////">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="@color/colorPrimary"
app:expandedTitleTextAppearance="@android:color/transparent"
android:fitsSystemWindows="true">
<ImageView
app:layout_collapseMode="parallax"
android:src="@drawable/climbing"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="250dp" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="10dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical>
<ListView
android:id="@+id/lstTask"
android:layout_width="match_parent"
android:layout_height="287dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:src="@drawable/edit"
app:backgroundTint="#6666ff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:pressedTranslationZ="12dp"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:elevation="6dp"
app:fabSize="mini"
android:id="@+id/action_add"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/savedHabits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add"
app:backgroundTint="#6666ff"
app:fabSize="mini"
app:elevation="6dp"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|left"
app:pressedTranslationZ="12dp" />
</android.support.design.widget.CoordinatorLayout>
你可以这样做
添加CustomListView
public class CustomListView extends ListView {
public CustomListView(Context context) {
super(context);
}
public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2
, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
更改xml代码
您可以更改此设置。
<ListView
android:id="@+id/lstTask"
android:layout_width="match_parent"
android:layout_height="287dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"/>
至
<!-- your package name-->
<com.your.app.utils.CustomListView
android:id="@+id/lstTask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"/>
您可以在添加属性时修复它
android:fillViewport=“true”
在android.support.v4.widget.NestedScrollView中
这是我的代码:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/titlesListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp" />
</LinearLayout >
</android.support.v4.widget.NestedScrollView>
它就像一个魔术。刚刚修复了列表视图中的android:layout\u height=“match\u parent”
。我很高兴能帮助你