我将这个库导入我的android项目。 ' com.balysv:材料纹波:1.0.1' 我想在listview中使用。涟漪工作正常,但当我触摸listview setinotemclicklistener不工作。这是我的代码。
public class Jobs extends Activity {
ListView listOfJobs;
LinearLayout llBack;
//boolean[] bolSubGroup = {false,false,false,true,false,true,false,true,true,false,false,false,true};
ArrayList<String> lstID = new ArrayList<String>();
ArrayList<String> lstTitle = new ArrayList<String>();
ArrayList<Integer> lstSubggroup = new ArrayList<Integer>();
String [] strTitle;
Integer [] intSubgroup ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.jobs);
ListJobs();
strTitle = new String[lstTitle.size()];
intSubgroup = new Integer[lstSubggroup.size()];
lstTitle.toArray(strTitle);
lstSubggroup.toArray(intSubgroup);
listOfJobs = (ListView) findViewById(R.id.lstv_Jobs);
LayoutAnimationController lac = new LayoutAnimationController(AnimationUtils.loadAnimation(Jobs.this,
R.animator.in_from_right2), 0.8f); //0.5f == time between appearance of listview item
listOfJobs.setLayoutAnimation(lac);
listOfJobs.setAdapter(new JobsAdapter1(this, R.layout.jobs_single_row,
R.id.txv_Jobs_SR, R.id.img_Jobs_SR, strTitle, intSubgroup));
listOfJobs.setOnItemClickListener(this);
llBack = (LinearLayout) findViewById(R.id.lil_Jobs_Top);
llBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(20);
finish();
}
});
listOfJobs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
});//*/
}
我的数组适配器
class JobsAdapter1 extends ArrayAdapter {
Activity context;
String[] items;
Integer[] arrows;
int layoutId;
int textId;
int imageId;
JobsAdapter1(Activity context, int layoutId, int textId, int imageId, String[] items, Integer[] arrows)
{
super(context, layoutId, items);
this.context = context;
this.items = items;
this.arrows = arrows;
this.layoutId = layoutId;
this.textId = textId;
this.imageId = imageId;
}
private class ViewHolder {
TextView txtitems;
ImageView img;
}
public View getView(int pos, View convertView, ViewGroup parent)
{
LayoutInflater inflater = context.getLayoutInflater();
ViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.jobs_single_row, null);
holder = new ViewHolder();
holder.txtitems = (TextView) convertView.findViewById(R.id.txv_Jobs_SR);
holder.img = (ImageView) convertView.findViewById(R.id.img_Jobs_SR);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.txtitems.setText(items[pos]);
if (arrows[pos] > 0)
{
holder.img.setImageResource(R.drawable.arrows_in);
}
else
{
holder.img.setImageDrawable(null);
}
return convertView;
}
}
我的单行xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.balysv.materialripple.MaterialRippleLayout
android:id="@+id/ripple"
android:layout_width="match_parent"
app:mrl_rippleColor="@color/yellow_ShahreHarah"
app:mrl_rippleOverlay="true"
app:mrl_rippleDimension="10dp"
app:mrl_rippleAlpha="0.2"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
app:mrl_rippleHover="true"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_height="fill_parent">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_margin="10dp"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/arrows_in"
android:id="@+id/img_Jobs_SR"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:textAppearance="?android:attr/textAppearanceListItem"
android:text="Large Text"
android:textDirection="rtl"
android:maxLines="1"
android:id="@+id/txv_Jobs_SR"
android:gravity="right"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:layout_marginTop="19dp"
android:layout_marginBottom="10dp"
android:layout_toRightOf="@+id/img_Jobs_SR"
android:layout_toEndOf="@+id/img_Jobs_SR" />
</RelativeLayout>
</com.balysv.materialripple.MaterialRippleLayout>
这是我的主要xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="@color/yellow_ShahreHarah"
android:id="@+id/lil_Jobs_Top"
android:layout_height="50dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:src="@drawable/arrows_in"
android:id="@+id/img_Jobs_Top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:textDirection="rtl"
android:textSize="20sp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="گروه های شغلی"
android:id="@+id/textView2" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="@drawable/shadow_left"
android:layout_alignParentTop="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:clickable="true"
android:id="@+id/lstv_Jobs" />
****************答案***** 我找到了答案
在单行xml文件中你必须像这样写
<com.balysv.materialripple.MaterialRippleLayout
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:orientation="vertical"
tools:ignore="UseCompoundDrawables"
app:mrl_rippleColor="#5b9bd5"
app:mrl_rippleOverlay="true"
app:mrl_rippleDimension="10dp"
app:mrl_rippleAlpha="0.2"
app:mrl_rippleHover="true"
app:mrl_rippleDelayClick="true"
android:background="#00deeaf6"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/lil_PIP_SR"
android:background="#00deeaf6"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_weight="1"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="10dp"
android:layout_height="wrap_content">
<ImageView
android:layout_width="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/phone_home"
android:id="@+id/img_PIP_HM_sr"
android:layout_height="30dp" />
</RelativeLayout>
</LinearLayout>
</com.balysv.materialripple.MaterialRippleLayout>
答案 0 :(得分:1)
尝试在app:mrl_rippleInAdapter="true"
中设置com.balysv.materialripple.MaterialRippleLayout
。它对我有用。