这是我的问题:我需要折叠包含一些textfield,button和LinearLayout的所有协调布局;但是当我实现我的代码(下面的代码)时,崩溃不会像我期望的那样。我希望在not collapsed layout上显示所有布局,当用户向下滚动时,折叠工具栏布局应显示一个布局:" partenza:...,arrivo:..."代替标题。
有什么想法吗?
<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>
答案 0 :(得分:0)
是的,这是可能的! 对于简单的可折叠布局,您可以执行以下操作:
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:
<?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>
同时检查this lib:
希望这有帮助!