Android 折叠工具栏布局如何工作?当工具栏崩溃时,如何对其进行个性化设置?
这是我的问题:我需要折叠所有包含文本字段、按钮和线性布局的协调布局;但是,当我实现我的代码(下面的代码)时,崩溃并不是我期望的结果。我希望在屏幕上显示所有布局,当用户向下滚动时,collaps工具栏布局应显示一个布局,标题为:“partenza:…,arrivo:…” 有什么想法吗Android 折叠工具栏布局如何工作?当工具栏崩溃时,如何对其进行个性化设置?,android,android-layout,android-collapsingtoolbarlayout,Android,Android Layout,Android Collapsingtoolbarlayout,这是我的问题:我需要折叠所有包含文本字段、按钮和线性布局的协调布局;但是,当我实现我的代码(下面的代码)时,崩溃并不是我期望的结果。我希望在屏幕上显示所有布局,当用户向下滚动时,collaps工具栏布局应显示一个布局,标题为:“partenza:…,arrivo:…” 有什么想法吗 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/androi
<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">
<android.support.design.widget.AppBarLayout
android:id="@+id/allAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimaryDark"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimaryDark"
android:subtitle="@string/subtitle_app"
android:title="@string/app_name"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="315dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="@style/InputTheme"
android:weightSum="2">
<RelativeLayout
android:id="@+id/inputPartenzaGroupBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:id="@+id/clearPartenzaBox"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dip"
android:background="@android:color/transparent" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/colorAccent">
<AutoCompleteTextView
android:id="@+id/tBoxPartenza"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorAccent"
android:hint="@string/example_text_1"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/white" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/inputArrivoGroupBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/inputPartenzaGroupBox"
android:layout_weight="1">
<Button
android:id="@+id/clearArrivoBox"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dip"
android:background="@android:color/transparent" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/colorAccent">
<AutoCompleteTextView
android:id="@+id/tBoxArrivo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorAccent"
android:hint="@string/example_text_2"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/white" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/btnInvertPosition"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:src="@drawable/ic_arrow" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btnSearchBus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="center"
android:text="@string/btn_text_search"
android:textColor="@color/colorAccent"
android:theme="@style/ThemeOverlay.AppCompat.Light" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainList"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</ListView>
是的,这是可能的!
对于简单的可折叠布局,您可以执行以下操作:
final TextView descriptionText = (TextView) view.findViewById(R.id.detail_description_content);
final TextView showAll = (TextView) view.findViewById(R.id.detail_read_all);
showAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showAll.setVisibility(View.INVISIBLE);
descriptionText.setMaxLines(Integer.MAX_VALUE);
}
});
XML:
也请检查:
希望这有帮助 你的可折叠布局的java代码是什么?@VivekSolanki现在没有,我只想知道是否可以这样做。你可以使用工具栏下面的两个布局并切换它们的可见性。。。要显示正在折叠的布局,只需删除Actionbar的标题,并将第一个布局设置为可通过文本视图等显示。如果要展开,请将可见性切换为“消失”,并使第二个布局可见。要制作动画,只需设置工具栏的高度并制作动画即可。这可能有助于你实现另一种效果。哇,这看起来很神奇,但还有一个问题,折叠的概念对于工具栏是相同的,或者有必要用另一种方式重新定义所有代码。因为一开始我的想法是创建一个折叠的工具栏布局@万岁!我不太清楚。但据我所知,您将需要动态/onScrolleEvent、工具栏折叠的动画。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/detail_description_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/detail_description_content"
android:maxLines="5"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/detail_read_all"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>