Android Fab有时才得到关注

Android Fab有时才得到关注,android,d-pad,Android,D Pad,我在使用D-pad测试我的应用程序的聚焦性时遇到问题。下面是我的应用程序的两个屏幕截图: 在左边的图片中,fab位于列表的“外部(或下方)”,在最后一个元素之后,它在向下导航时获得焦点,因此在本例中一切正常。问题来自右侧的图像。晶圆厂是“内部”的列表视图,因此(我想,但我不确定)它从来没有得到关注。有什么可以做的吗 一个改进是,无论晶圆厂位于布局中的哪个位置,晶圆厂将始终在列表之前(即紧跟在选项卡之后)获得焦点,但问题是我不知道如何做到这一点,因为Android决定了我布局的焦点顺序。 任何

我在使用D-pad测试我的应用程序的聚焦性时遇到问题。下面是我的应用程序的两个屏幕截图:

在左边的图片中,fab位于列表的“外部(或下方)”,在最后一个元素之后,它在向下导航时获得焦点,因此在本例中一切正常。问题来自右侧的图像。晶圆厂是“内部”的列表视图,因此(我想,但我不确定)它从来没有得到关注。有什么可以做的吗

一个改进是,无论晶圆厂位于布局中的哪个位置,晶圆厂将始终在列表之前(即紧跟在选项卡之后)获得焦点,但问题是我不知道如何做到这一点,因为Android决定了我布局的焦点顺序。 任何帮助都将不胜感激

更新: fragment_main.xml

  <?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"

    tools:mContext=".FragmentMain">
    <!---marginBottom for ads-->
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpagerMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        android:layout_marginBottom="60dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabsMain"
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:layout_marginTop="50dp"
        android:background="?attr/colorPrimary"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom"
        app:tabGravity="fill"
        app:tabIndicatorHeight="5dp"
        app:tabMode="fixed"
        app:tabPaddingTop="60dp"
        app:tabSelectedTextColor="@android:color/white"
        app:tabTextAppearance="@style/TabTextAppearance" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="330dp"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">


            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="86dp"
                android:background="@color/white"
                android:orientation="vertical">


                    <com.github.mikephil.charting.charts.LineChart
                        android:id="@+id/chart"
                        android:layout_width="match_parent"
                        android:layout_height="250dp"
                        android:layout_marginLeft="5dp"/>

                    <ProgressBar
                        android:id="@+id/progressBar"
                        android:background="@drawable/progress"
                        android:layout_width="60dp"
                        android:layout_height="60dp"
                        android:layout_gravity="center"

                        android:visibility="visible"
                        tools:visibility="visible">

                    </ProgressBar>
                </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay"


                />


        </android.support.design.widget.CollapsingToolbarLayout>


    </android.support.design.widget.AppBarLayout>

    <!-- http://antonioleiva.com/floating-action-button/-->
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabMain"
        android:focusable="true"
        android:background="@drawable/selector_focusable_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end|right"
        android:layout_marginBottom="60dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp"
        android:src="@drawable/plus_48"
        app:pressedTranslationZ="12dp"
        app:rippleColor="@color/colorAccent"/>

    <include layout="@layout/ad_bottom_bar"
        android:id="@+id/advBottomBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"

       />
</android.support.design.widget.CoordinatorLayout>

security_item.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- for statedrawable list to work we need to set background in cardview and
 immediate linearlayout. Also set android.clickable in cardview AND
 android:duplicateParentState in linearlayout-->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:background="@drawable/selector_security"
    android:clickable="true"
    android:nextFocusRight="@+id/overflow"
    app:contentPadding="@dimen/si_card_view_content_padding"
    android:id="@+id/cardView"
    card_view:cardCornerRadius="0dp"
    card_view:cardElevation="@dimen/si_card_view_elevation"
    card_view:cardUseCompatPadding="true"
    >

    <LinearLayout
        android:id="@+id/linearParent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:nextFocusRight="@+id/overflow"
        android:duplicateParentState="true"
        android:background="@drawable/selector_security">

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

            <TextView
                android:id="@id/ticker"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"

                tools:text="GOOG" />

            <TextView
                android:id="@+id/market"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:gravity="start"
                tools:text="EQUITY" />
            <ImageView
                android:id="@+id/overflow"
                android:focusable="true"
                android:nextFocusLeft="@+id/cardView"
                android:nextFocusDown="@+id/cardView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/selector_overflow_mini"
                android:tint="@color/gray700"
                android:src="@drawable/ic_overflow"/>
        </LinearLayout>

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

            <com.carlos.capstone.customcomponents.AutoResizeTextView
                android:id="@+id/securityName"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:textStyle="bold"
                tools:text="Alphabet Inc." />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:gravity="end"
                android:textSize="@dimen/si_label_day"
                android:text="Day(max/min)"
                tools:text="Day(max/min)" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/price"
                android:layout_marginTop="3dp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:textSize="@dimen/si_price_text_size"
                tools:text="710,89" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.9"
                android:orientation="vertical">



                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:orientation="horizontal">

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

                    <com.carlos.capstone.customcomponents.AutoResizeTextView
                        android:id="@+id/percentChange"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:layout_marginTop="@dimen/si_percent_margin_top"
                        android:textSize="@dimen/si_percent_text_size"
                        android:gravity="end"
                        tools:text="-110.21%" />
                    </LinearLayout>

                </LinearLayout>


            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:orientation="vertical">

                <com.carlos.capstone.customcomponents.AutoResizeTextView
                    android:id="@+id/dayMax"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:textColor="@color/gray400"
                    android:gravity="end"
                    tools:text="716,49" />

                <com.carlos.capstone.customcomponents.AutoResizeTextView
                    android:id="@+id/dayMin"
                    android:paddingTop="@dimen/si_min_padding_top"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:gravity="end"
                    android:textColor="@color/gray400"
                    tools:text="706,02" />


            </LinearLayout>

        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

您可以创建一个单独的
布局
并将晶圆厂放在那里。这将迫使人们始终看到该部分

比如说

<LinearLayout>
    //list stuff here
    <LinearLayout>
    //fab stuff
    </LinearLayout>
</LinearLayout>

//在这里列出东西
//晶圆厂材料

您可以创建一个单独的
布局
并将晶圆厂放在那里。这将迫使人们始终看到该部分

比如说

<LinearLayout>
    //list stuff here
    <LinearLayout>
    //fab stuff
    </LinearLayout>
</LinearLayout>

//在这里列出东西
//晶圆厂材料

可能您的xml植入错误发布您的xml听力。我在首选项列表中遇到了相同的问题,这是因为下面的列表项获得了焦点,而不是FAB。这就是为什么它在第一个屏幕截图上工作。@Carlos你在所有版本上都遇到这个问题吗?这个问题发生在旧的API版本上,而不是最新的版本。对不起,我没有在以前的版本中测试它,这个版本是22@Yoann是的,这就是问题所在,但如何解决呢?可能你的xml植入是错误的发布你的xml听力。我在首选项列表上也遇到了同样的问题,发生这种情况是因为下面的列表项得到的是焦点,而不是晶圆厂。这就是为什么它在第一个屏幕截图上工作。@Carlos你在所有版本上都遇到这个问题吗?这个问题发生在旧的API版本上,而不是最新的版本。对不起,我没有在以前的版本中测试它,这个版本是22@Yoann是的,这就是问题所在,但是如何解决呢?这两个布局在不同的片段中。此外,用户需要导航到列表的末尾才能看到工厂,如果列表是一个或两个元素,没有问题,但在较大的列表中,晶圆厂放在末尾,这不是晶圆厂的良好行为,应该始终清晰可见。无论如何,谢谢你的回答这两个布局是在不同的碎片。此外,用户需要导航到列表的末尾才能看到晶圆,如果列表是一个或两个元素,没有问题,但是在较大的列表上晶圆放在末尾,这不是晶圆的好行为,应该总是容易看到。不管怎样,谢谢你的回答