アクティビティには最初の試行ではクリックされないが、2回目以降はクリックされるボタンがいくつかあります。ボタンは最初のクリックにフォーカスを当てて、2回目以降は実際に押されているようです。これらのボタンが初めてクリックされない理由は何ですか? この動作は、私の活動の一番下にあるボタンによってのみ表示されることに気付きました。私MainActivity.classで最初の試行でボタンがクリックされない
activity_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"
tools:context="com.me.proj.view.activities.MallActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
app:title=" "
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager_mall_showcase_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include layout="@layout/info_card" />
<include layout="@layout/photo_card" />
<include layout="@layout/address_card" />
<include layout="@layout/opening_hours_card" />
<include layout="@layout/review_card" /> <!-- Button in this file has the problem-->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
review_card.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="0.5dp"
card_view:cardMaxElevation="1dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_marginTop="7dp"
android:background="@color/colorWhite"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite">
<TextView
android:id="@+id/txt_rating"
android:background="@drawable/blue_button_background"
android:text="3.8"
android:textColor="@color/colorWhite"
android:layout_marginTop="10dp"
android:textSize="24sp"
android:gravity="center"
android:layout_marginStart="10dp"
android:layout_width="60dp"
android:layout_height="40dp" />
<TextView
android:id="@+id/txt_reviews_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/primary_text"
android:textSize="16sp"
android:layout_toEndOf="@+id/txt_rating"
android:layout_marginStart="20dp"
android:textStyle="bold"
android:paddingTop="1dp"
android:layout_alignTop="@+id/txt_rating"
android:text="Based on 98 reviews"/>
<TextView
android:id="@+id/txt_read_all_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read All Reviews"
android:layout_alignStart="@id/txt_reviews_title"
android:layout_toEndOf="@id/txt_rating"
android:layout_alignBottom="@id/txt_rating"
android:gravity="bottom"
android:paddingBottom="1dp"
android:textColor="@color/red"
android:layout_below="@id/txt_reviews_title"/>
<View
android:id="@+id/view_dummy1"
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:layout_below="@id/txt_read_all_reviews"
android:layout_marginTop="10dp"
android:background="@color/divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginStart="16dp"
android:layout_below="@+id/view_dummy1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/txt_how_did_your_visit_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How did your visit go?"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="@color/primary_text" />
<TextView
android:id="@+id/txt_tell_everyone_about_it"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tell everyone about it!"
android:layout_marginTop="5dp"
android:textColor="@color/secondary_text"
android:textSize="12sp"
/>
</LinearLayout>
<!--This got some problem-->
<Button
android:id="@+id/btn_add_review"
android:layout_width="0dp"
android:layout_height="40dp"
android:text="Add Your Review"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:textAllCaps="false"
android:textColor="@color/colorWhite"
android:background="@drawable/blue_button_background"
android:layout_weight="0.5"/>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_add_review).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "clicked", Toast.LENGTH_SHORT).show();
}
});
}
あなたは、「この行動は自分の活動の最中にあるボタンによってのみ表示されることに気付きました。 ** btn_add_review **ボタンをレイアウトの上部に配置すると、review_card **に同じ問題がありますか? –
いいえ、review_cardを一番上に置くとボタンがクリックされますが、カードの底に配置されたボタンは、以前はそこになかった問題を今すぐに開始しました。 –
下部に行くカードはどれもフォーカスを失い、したがって2回クリックする必要があります。最初のところフォーカスが失われた理由について、私の周りに頭を浮かべることはできません。 –