CollapsingToolbarLayout
の中に3つのボタンがあります。展開するときは、表示されている画像ギャラリーのフィルタを変更するか、編集ダイアログをポップアップ表示させます。一貫性のない結果が得られました。ボタンは断続的にクリックに反応するだけでした。CollapsingToolbarLayoutのボタンのクリック領域が小さすぎるのはなぜですか?
結局のところ、クリック可能な領域がビューのクライアントの矩形よりずっと小さいということがわかりました。横方向では、通常のように見えますが、クリック可能な領域はボタンよりもはるかに短くなっています。私は限界までのように、かなり正確な取得することができたエミュレータでは:
あなたは、通常、左から右へ、しかし、上から下へは間違っているそれらに触れることができます。
私は、このレイアウトを、ドキュメント、公式ガイド、オンラインチュートリアル、およびオープンソースコードの例のさまざまなスニペットから集めようとしています。私はファンシーサポート/デザインレイアウトがどのように一緒に機能するか、あるいは組み合わせたときにすべての設定属性が正確に何をするのかを完全に理解していないので、修正が属性または2つの単純な変更になる可能性は完全にあります。ここに私のレイアウトは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
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/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="?android:actionBarSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
android:background="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
android:theme="@style/Widget.Design.CollapsingToolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="32dp"
android:paddingBottom="64dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="none"
android:background="@android:color/transparent"
android:orientation="horizontal">
<ImageButton android:id="@+id/btnTags"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_tag"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
<ImageButton android:id="@+id/btnAlbums"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_albums"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
<ImageButton android:id="@+id/btnNewAlbum"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_new_album"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarMain"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="@string/app_name"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/LouvreTheme.ToolbarStyle"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
android:id="@+id/recyclerAlbumGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="?android:attr/background"
app:rrvLayoutType="Grid"
app:rrvGridLayoutSpanCount="@integer/grid_span"
app:rrvIsRefreshable="false"
app:rrvSwipeToDelete="false" />
</android.support.design.widget.CoordinatorLayout>
その後、私のonViewCreated()
に、私はボタンOnClickListenerをそれぞれ割り当てます。私はそれらを確実に、そして予想通りに引き起こすことができますが、上に描かれた狭い縦のバンドをクリックすることによってのみ、それらを引き起こすことができます。
対処法との調整は私はすでに試してみました:
- が
FloatingActionButton
秒にImageView
sからの切り替え、そして最終的にImageButton
のボタンを変更それらのすべて - 含む
- 異なるビューに叩き
android:fitsSystemWindows="true"
、wrap_content
から表示されているVectorDrawable
に定義されているサイズを明示的に指定する ボタン
- は、各ボタン1.0の
layout_weight
を作成し、ボタンを収容LinearLayout
上paralax
とnone
など様々app:layout_collapseMode
を試みる3.0 - に合計を設定すると
- が同じ明示的なサイズに
LinearLayout
にandroid:minHeight
を設定します。いいえ満足のいく答えがこれまで提供されなかったAppBarLayout and CollapsingToolbarLayout not able to contain Button?、崩壊領域の外側のボタンを移動するだけで回避策:
私はSOに見つけることができましたのみで同様の問題はこれです。
思考?
はたぶんリニアレイアウトは縮小:paddingTop =「32dp」 アンドロイド:paddingBottomの=「64DP - あなたがここにアンドロイドをレイアウトの色を追加することでこれをテストすることができます:背景=」@アンドロイド:色をどのようなサイズであるかを知るために/ transparentを使用します - マージンを代わりに使用するか、リニアレイアウトを相対レイアウトでラップします。例えば相対レイアウト---リニアレイアウト - >あなたのボタン – Tasos
@Tasos Setting and android:background = LinearLayout上の "@android:color/holo_red_dark" 'は実際には私が期待していたものではないツールバーのレイアウト全体を赤にしますが、ボタンの中央では間違いなく切り詰めるわけではありません –
Ok。 LinearLayoutにあり、それが役立つかどうかを確認してください--- android:layout_centerInParent = "true" andro id:gravity = "center_horizontal" android:orientation = "vertical" – Tasos