Ich habe ein Problem beim Testen der Fokussierbarkeit meiner App mit D-Pad. Hier gibt es zwei Screenshots meiner App:Fab bekommt nur manchmal Fokus
Im Bild von der linken Seite, die fab ist „außen (oder unten)“ die Liste und nach dem letzten Elemente erhält es den Fokus, wenn nach unten navigieren, also ist in diesem Fall alles in Ordnung. Das Problem kommt mit dem Bild der rechten Seite. Die Fab ist "innerhalb" der ListView und aus diesem Grund (ich denke, aber ich bin mir nicht sicher) wird es nicht immer den Fokus bekommen. Kann man etwas dagegen tun?
Eine Erweiterung wäre, dass die Fab den Fokus immer vor der Liste (dh unmittelbar nach den Tabs) bekommen würde, egal wo die Fab im Moment im Layout positioniert ist, aber das Problem ist, dass ich Ich weiß, wie es geht, da Android die Fokusreihenfolge meines Layouts bestimmt. Jede Hilfe würde sehr geschätzt werden.
UPDATE: 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>
können Ihre xml der Implantation ist falsch Ihre xml hören. –
Veröffentlichen Sie Ihren XML-Code. –
Ich habe das gleiche Problem in einer Voreinstellungsliste, es passiert, weil das Listenelement unten den Fokus erhält und nicht das FAB. Deshalb wird am ersten Screenshot gearbeitet. –