3

您好我在设计中面临一个问题,其 xml 如下。问题是我在嵌套滚动视图中使用了两个文本视图、按钮和回收器视图。当我运行时,这个代码视图是从 recyclerview 开始的,但是当我向下滚动时,那些 textview,button 是可见的。请帮助我如何从第一个视图开始查看,并避免在移动设备中显示视图时直接关注 recyclerview。我怎么解决这个问题?帮我。对不起我糟糕的英语。

<android.support.v4.widget.NestedScrollView
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="false">

                    <LinearLayout
                        android:id="@+id/llMainContainer"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:padding="@dimen/padding_10">

                        <com.xyz.ui.widget.CustomEditTextView
                            android:id="@+id/etEmail"
                            style="@style/Widget.xyz.EditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="@string/order_mobile_number"
                            android:inputType="text"
                            app:fontTextStyle="3" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                            android:weightSum="2">

                            <com.xyz.ui.widget.CustomEditTextView
                                android:id="@+id/etDateFrom"
                                style="@style/Widget.xyz.EditText"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/spacing_normal"
                                android:layout_weight="1"
                                android:drawableLeft="@drawable/ic_calendar"
                                android:drawablePadding="@dimen/spacing_normal"
                                android:drawableStart="@drawable/ic_calendar"
                                android:editable="false"
                                android:focusable="false"
                                android:hint="@string/date_from"
                                android:inputType="text"
                                app:fontTextStyle="3" />

                            <com.xyz.ui.widget.CustomEditTextView
                                android:id="@+id/etDateTo"
                                style="@style/Widget.xyz.EditText"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="@dimen/margin_left_10"
                                android:layout_marginStart="@dimen/margin_left_10"
                                android:layout_marginTop="@dimen/spacing_normal"
                                android:layout_weight="1"
                                android:drawableLeft="@drawable/ic_calendar"
                                android:drawablePadding="@dimen/spacing_normal"
                                android:drawableStart="@drawable/ic_calendar"
                                android:editable="false"
                                android:focusable="false"
                                android:hint="@string/date_to"
                                android:inputType="text"
                                app:fontTextStyle="3" />
                        </LinearLayout>

                        <com.xyz.ui.widget.CustomTextView
                            android:id="@+id/txtGenerate"
                            style="@style/Theme.xyz.Button"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/spacing_normal"
                            android:text="@string/generate_report"
                            android:textAllCaps="false"
                            app:fontTextStyle="1" />

                        <android.support.v7.widget.RecyclerView
                            android:id="@+id/rvPendingOrders"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/spacing_micro" />

                    </LinearLayout>

                </android.support.v4.widget.NestedScrollView>
4

3 回答 3

1

我按照以下方式管理我的代码,它对我来说工作正常。看看完整的布局代码:

<LinearLayout 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:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="false"
    android:orientation="vertical"
    tools:context=".order.Order">
    <LinearLayout
        android:id="@+id/headerbar"
        style="@style/HeaderBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:orientation="vertical"
        android:visibility="visible">

        <include layout="@layout/toolbar_actionbar" />
        <!-- placeholder, empty except on L -->
    </LinearLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="false">
        <!-- Main layout -->
        <FrameLayout
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="false"
            app:shadowDrawable="@drawable/header_shadow">

            <android.support.v4.widget.NestedScrollView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <LinearLayout
                    android:id="@+id/llMainContainer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:padding="@dimen/padding_10">

                    <EditTextView
                        android:id="@+id/etEmail"
                        style="@style/Widget.xyz.EditText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/order_mobile_number"
                        android:imeOptions="actionDone"
                        android:inputType="text"
                        app:fontTextStyle="3" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:weightSum="2">

                        <EditTextView
                            android:id="@+id/txtDateFrom"
                            style="@style/Widget.xyz.EditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/spacing_normal"
                            android:layout_weight="1"
                            android:drawableLeft="@drawable/ic_calendar"
                            android:drawablePadding="@dimen/spacing_normal"
                            android:text="@string/date_from"
                            android:focusable="false"
                            android:editable="false"
                            app:fontTextStyle="3" />

                        <EditTextView
                            android:id="@+id/txtDateTo"
                            style="@style/Widget.xyz.EditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="@dimen/margin_left_10"
                            android:layout_marginTop="@dimen/spacing_normal"
                            android:layout_weight="1"
                            android:drawableLeft="@drawable/ic_calendar"
                            android:drawablePadding="@dimen/spacing_normal"
                            android:focusable="false"
                            android:editable="false"
                            android:text="@string/date_to"
                            app:fontTextStyle="3" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/txtGenerate"
                        style="@style/Theme.xyz.Button"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/spacing_normal"
                        android:text="@string/generate_report"
                        android:textAllCaps="false"
                        app:fontTextStyle="1" />

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/rvPendingOrders"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/spacing_micro" />

                </LinearLayout>

            </android.support.v4.widget.NestedScrollView>
        </FrameLayout>
        <!-- Nav drawer -->
        <include layout="@layout/navdrawer" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>
于 2016-03-07T13:46:51.430 回答
0

添加

android:descendantFocusability="blocksDescendants"

像这样在LinearLayout里面

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:orientation="vertical">
于 2018-08-11T10:40:14.900 回答
0

使用 EditText 作为 NestedScrollView 中的第一个元素可能会对您有所帮助。

    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/blur"
            android:orientation="vertical">

            <EditText
                android:layout_width="0px"
                android:layout_height="0px"
                android:focusable="true"
                android:focusableInTouchMode="true" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/itemsHolder"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

注意:启动活动时必须隐藏键盘

于 2016-08-21T07:38:23.980 回答