Android 使其可见后,RecyclerView将显示在屏幕顶部
我有一个片段,布局如下:Android 使其可见后,RecyclerView将显示在屏幕顶部,android,android-recyclerview,android-spinner,Android,Android Recyclerview,Android Spinner,我有一个片段,布局如下: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_background"
android:layoutDirection="rtl">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="170dp"
android:background="@color/orange"
android:paddingRight="20dp"
app:collapsedTitleGravity="right|center_vertical"
app:collapsedTitleTextAppearance="@style/CollapsedAppBar"
app:contentScrim="@color/orange"
app:expandedTitleGravity="bottom|center_horizontal"
app:expandedTitleTextAppearance="@style/CollapsedAppBar"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:layout_marginLeft="10dp"
android:src="@drawable/ic_lock_profile_prime"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layoutDirection="ltr"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/costs_nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="168dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/spinner_background">
<Spinner
android:id="@+id/wallet_spinner"
style="@style/Widget.AppCompat.DropDownItem.Spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layoutDirection="rtl" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/cost_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none" />
<android.support.v7.widget.RecyclerView
android:id="@+id/payment_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
android:layout_weight="1"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none" />
<android.support.v7.widget.RecyclerView
android:id="@+id/gift_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="gone"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none" />
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/no_records"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="@dimen/bottom_navigation_height"
android:layout_gravity="bottom"
android:background="@color/blue_2"
android:padding="10dp">
<TextView
android:id="@+id/rent_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:paddingBottom="5dp"
android:drawablePadding="10dp"
android:drawableRight="@drawable/ic_plus"
android:textColor="@color/colorPrimary"
android:textSize="15sp" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
我想在选择了微调器的特定项时,使每个回收视图可见,并隐藏其他回收视图。第一次选择每个项目是可以的,但从第二次选择项目后,RecyclerView转到屏幕顶部,微调器转到工具栏后面。我的微调器代码实现为:
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
switch (position) {
case 0:
if (costs != null) {
paymentRecyclerView.setVisibility(View.GONE);
costRecyclerView.setVisibility(View.VISIBLE);
} else {
getCostData();
}
break;
case 1:
if (payments != null) {
costRecyclerView.setVisibility(View.GONE);
paymentRecyclerView.setVisibility(View.VISIBLE);
} else {
getPaymentData();
}
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
spinner.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图selectedItemView、整型位置、长id){
开关(位置){
案例0:
如果(成本!=null){
paymentRecyclerView.setVisibility(View.GONE);
costRecyclerView.setVisibility(View.VISIBLE);
}否则{
getCostData();
}
打破
案例1:
如果(付款!=null){
costRecyclerView.setVisibility(View.GONE);
paymentRecyclerView.setVisibility(View.VISIBLE);
}否则{
getPaymentData();
}
打破
}
}
@凌驾
未选择公共无效(AdapterView父视图){
//你的代码在这里
}
});
如何解决我的问题?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
与使用三个recyclerViews不同,更好的方法是在layout和onItemClick微调器中使用单个recycler视图只需更改同一RecyclerView上的适配器,或者您可以更改同一适配器中的数据并调用notifyDataSetChangedWhy这样更好?与使用三个recyclerViews不同,更好的方法是使用单个recyclerViewslayout中的recycler视图和微调器的onItemClick只需更改同一recylcerview上的适配器,或者您可以更改同一适配器中的数据并调用notifyDataSetChangedWhy this this this better?现在我无法选择EditText。现在我无法选择EditText。