我有一个有儿童波纹布局的cardview。在波纹布局下,我有布局和文本视图。 在我的课堂上,我在涟漪布局上添加了onclick监听器。但我想在textview上进行onclick事件,这是在涟漪效应内部。
正在发生的事情:点击布局会启动ripple onclick代码,而Textview onclick代码永远不会触发。
CardView XML代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="140dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp">
<com.gc.materialdesign.views.LayoutRipple
android:id="@+id/ripplelayout"
android:layout_width="match_parent"
android:background="#f5f5f5"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/header_ll"
android:layout_width="match_parent"
android:layout_height="65dp"
android:clickable="true"
android:weightSum="3.5"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="70dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.4"
android:weightSum="0.4"
android:layout_marginStart="5dp"
android:layout_marginTop="2dp">
<TextView
android:id="@+id/job_number"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0.1"
android:gravity="center_vertical"
android:text="TN1234"
android:textColor="#000"
android:textSize="12sp" />
<TextView
android:id="@+id/job_time"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:gravity="top"
android:text="mm,hh:mm"
android:textColor="#000"
android:textSize="12sp" />
</LinearLayout>
<FrameLayout
android:id="@+id/job_frame"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_weight="2.3"
android:weightSum="2.3"
android:layout_marginTop="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/locationimage"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:gravity="center"
android:layout_weight="0.3"
android:layout_marginTop="10dp"
android:clickable="true"
android:src="@drawable/location"/>
<android.support.v7.widget.AppCompatTextView
android:textSize="11sp"
android:id="@+id/job_addresstext"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:textColor="#74aadc"
android:layout_weight="2.0"
android:focusable="true"
android:ellipsize="end"
android:textStyle="bold"
android:clickable="true"
android:focusableInTouchMode="true"
android:layout_marginStart="0dp"
android:text="Street Name, Landmark\n Address , Lorem Ipsum"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="70dp"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.9"
android:weightSum="0.9"
android:layout_marginTop="2dp">
<ImageView
android:id="@+id/timerimage"
android:layout_width="wrap_content"
android:layout_weight="0.1"
android:layout_height="20dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:src="@drawable/timer"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/job_timertext"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#000"
android:layout_weight="0.7"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:textSize="12sp"
android:text="HH:MM"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@+id/header_ll"
android:layout_marginStart="5dp">
<TextView
android:id="@+id/instruction_label"
android:layout_width="70dp"
android:layout_height="30dp"
android:gravity="center"
android:layout_marginTop="1dp"
android:textStyle="bold"
android:text="XYZ wrote:"
android:textColor="#000"
android:textSize="12sp" />
<TextView
android:id="@+id/instruction_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum"
android:textColor="#727272"
android:inputType="textMultiLine"
android:textSize="12sp" />
</LinearLayout>
<!--</RelativeLayout>-->
</com.gc.materialdesign.views.LayoutRipple>
</android.support.v7.widget.CardView>
</RelativeLayout>
涟漪效应监听器
holder.ripplelayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SingleTon.getInstance().setWorkDescHolder(mDataset.get(position).descHolder);
FragmentManager fragmentManager = ((FragmentActivity) mAct).getSupportFragmentManager();
FragmentTransaction ft = ((FragmentActivity) mAct).getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.glide_fragment_horizontal_in, R.anim.glide_fragment_horizontal_out);
ft.replace(R.id.content_frame1, new DetailsFragment(), "persondetails");
ft.addToBackStack("persondetails");
// Start the animated transition.
ft.commit();
}
});
框架布局,其中textview存在于所需的点击事件中:
holder.frameLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String map = "http://maps.google.co.in/maps?q=" + mDataset.get(position).address;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
mAct.startActivity(intent);
}
});
}
我尝试使用框架布局进行textview但没有任何工作。 请帮我提供建议和代码。