Нажатие кнопки и ее родительский макет Нажмите кнопку конфликта - PullRequest
0 голосов
/ 06 июня 2018

У меня есть кнопка внутри Framelayout.Моя цель состоит в том, чтобы изменить элемент просмотра пейджера по нажатию кнопки и в любом месте за пределами нажатия кнопки, я хочу показать меню внизу.Проблема, с которой я сталкиваюсь, заключается в том, что, когда я добавляю список onclick на родительский каркас, мои кнопки не работают.вместо кнопок, щелчок рамки кадра действует и показывает мое меню.

Вот мой код слушателя onclick:

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.source1:
            // Change viewpager page
            if (((MainActivity) getActivity()).getViewPager() != null) {
                SourceCommunicator sc = new SourceCommunicator();
                sc.referenceUrl = news.getSources().get(0).getSiteUrl();
                EventBus.getDefault().post(sc);
                ((MainActivity) getActivity()).getViewPager().setCurrentItem(2);
            }
            break;
        case R.id.container:

            // Show menu at the bottom
            EventBus.getDefault().post(new Communicator());
            if (showContentWriter) {
                referenceView.setVisibility(View.VISIBLE);
                writterView.setVisibility(View.GONE);
            } else {
                referenceView.setVisibility(View.GONE);
                writterView.setVisibility(View.VISIBLE);
            }
            showContentWriter = !showContentWriter;
            break;
        default:
            break;
    }
}

Мой файл макета

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/container"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragments.ShortFragment">

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        card_view:cardCornerRadius="15dp">

        <!-- TODO: Update blank fragment layout -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:id="@+id/previewView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/previewImageView"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:layout_alignParentTop="true"
                    android:scaleType="centerCrop" />

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:background="@drawable/gradient_bg" />
            </RelativeLayout>

            <LinearLayout
                android:id="@+id/newsLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/relatedNewsView"
                android:layout_below="@+id/previewView"
                android:layout_margin="20dp"
                android:orientation="vertical">

                <com.shongkhipto.shonkhipto.Utlis.BanglaTextView
                    android:id="@+id/titleView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Three astronauts return to Earth after 168 days in space"
                    android:textColor="@android:color/black"
                    android:textSize="24dp"
                    android:textStyle="bold" />

                <com.shongkhipto.shonkhipto.Utlis.BanglaTextView
                    android:id="@+id/descriptionView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="After spending 168 days aboard the International Space Station, NASA astronaut Scott Tingle, Japan's Norishige Kanai and Russian cosmonaut Anton Shkaplerov landed in Kazakhstan on Sunday. While Tingle and Kanai conducted separate spacewalks, Shkaplerov did a record-setting 8-hour-long spacewalk. It was Tingle and Kanai's first mission, while Shkaplerov has logged 532 days on three flights."
                    android:textSize="18dp" />

                <LinearLayout
                    android:id="@+id/referenceView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="vertical">

                    <com.shongkhipto.shonkhipto.Utlis.BanglaTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="আরো পড়ুন"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="10dp"
                        android:textSize="18dp" />

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

                        <ImageButton
                            android:id="@+id/source1"
                            android:layout_width="60dp"

                            android:layout_height="30dp"
                            android:layout_marginLeft="10dp"
                            android:background="@null"
                            android:scaleType="fitCenter"
                            android:visibility="gone"
                            app:srcCompat="@drawable/baseline_keyboard_arrow_left_24" />

                        <ImageButton
                            android:id="@+id/source2"
                            android:layout_width="60dp"
                            android:layout_height="30dp"
                            android:layout_marginLeft="10dp"
                            android:background="@null"
                            android:scaleType="fitCenter"
                            android:visibility="gone"
                            app:srcCompat="@drawable/baseline_keyboard_arrow_left_24" />

                        <ImageButton
                            android:id="@+id/source3"
                            android:layout_width="60dp"
                            android:layout_height="30dp"
                            android:layout_marginLeft="10dp"
                            android:background="@null"
                            android:scaleType="fitCenter"
                            android:visibility="gone"
                            app:srcCompat="@drawable/baseline_keyboard_arrow_left_24" />

                        <ImageButton
                            android:id="@+id/source4"
                            android:layout_width="60dp"
                            android:layout_height="30dp"
                            android:layout_marginLeft="10dp"
                            android:background="@null"
                            android:scaleType="fitCenter"
                            android:visibility="gone"
                            app:srcCompat="@drawable/baseline_keyboard_arrow_left_24" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/writterView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp">

                    <com.shongkhipto.shonkhipto.Utlis.EnglishTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Short by"
                        android:textSize="18dp"
                        android:textStyle="bold" />

                    <com.shongkhipto.shonkhipto.Utlis.BanglaTextView
                        android:id="@+id/writerTextView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text=" Shifa Naseer"
                        android:textSize="18dp" />
                </LinearLayout>
            </LinearLayout>

            <RelativeLayout
                android:id="@+id/relatedNewsView"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true"
                android:background="@color/colorAccent"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/relatedNewsImageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/error" />

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/full_gradient_bg" />

                <com.shongkhipto.shonkhipto.Utlis.BanglaTextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:layout_margin="10dp"
                    android:text="World must stand up to US 'bullying': Iran Foreign Minister"
                    android:textColor="@android:color/white"
                    android:textSize="12dp" />
            </RelativeLayout>

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

</FrameLayout>
...