【发布时间】:2018-07-16 07:20:10
【问题描述】:
您好,我是 kotlin 的新手,我遇到了一个非常奇怪的问题。我有一个简单的 ListView 填充了一些子布局! 我在 XML 中的 ListView 标记是:
<ListView
android:id="@+id/invoicesList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="0dp"/>
我的适配器是:
class InvoicesListAdapter(context: Context, activity: Activity, resource: Int, list: ArrayList<InvoicesListModel>) : ArrayAdapter<InvoicesListModel>(context, resource, list) {
var list: ArrayList<InvoicesListModel> = list
var activity: Activity? = null
init {
this.activity = activity
}
private class ViewHolder(row: View?) {
var serviceName: BakcellTextViewNormal? = null
var endirimValue: BakcellTextViewNormal? = null
var miqdarValue: BakcellTextViewNormal? = null
var vahidValue: BakcellTextViewNormal? = null
var mablaqValue: BakcellTextViewNormal? = null
var camiValue: BakcellTextViewNormal? = null
init {
this.serviceName = row?.findViewById(R.id.serviceValue)
this.endirimValue = row?.findViewById(R.id.endirimValue)
this.miqdarValue = row?.findViewById(R.id.miqdarValue)
this.vahidValue = row?.findViewById(R.id.vahidValue)
this.mablaqValue = row?.findViewById(R.id.mablaqValue)
this.camiValue = row?.findViewById(R.id.camiValue)
}//init ends
}// class ViewHolder ends
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view: View?
val viewHolder: ViewHolder
if (convertView == null) {
val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
view = inflater.inflate(R.layout.invoices_list_layout, null)
viewHolder = ViewHolder(view)
view?.tag = viewHolder
} else {
view = convertView
viewHolder = view.tag as ViewHolder
}
var listModel = getItem(position)
viewHolder.serviceName!!.text=listModel.serviceName
viewHolder.miqdarValue!!.text=listModel.miqdarValue
viewHolder.vahidValue!!.text=listModel.vahidValue
viewHolder.mablaqValue!!.text=listModel.mablaqValue
viewHolder.endirimValue!!.text=listModel.endirimValue
viewHolder.camiValue!!.text=listModel.camiValue
//send arrow click
return view as View
}//getview ends
}//class ends
我的适配器/ListView 项目布局是:
<?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">
<!--nested container-->
<RelativeLayout
android:id="@+id/ripple"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/_10sdp"
android:paddingTop="@dimen/_10sdp">
<RelativeLayout
android:id="@+id/childLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_20sdp"
android:layout_marginRight="@dimen/_20sdp"
android:orientation="horizontal">
<!--col1-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4.2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/serviceValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Blackberry Service"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col2-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/miqdarValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="12345"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col3-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4.9">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/vahidValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="saat:den:san"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col4-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/mablaqValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="98.2"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col5-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3.3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/endirimValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="0.0"
android:textColor="@color/colorTextBlack"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col6-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/camiValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1125.7"
android:textColor="@color/colorTextBlack"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<!--//nested container-->
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/ripple"
android:layout_marginLeft="@dimen/_45sdp"
android:layout_marginRight="@dimen/_45sdp"
android:background="@color/colorSeperator"></View>
</RelativeLayout>
问题是当我点击 id=ripple 的相对布局时,我想显示波纹! 我知道我可以设置:
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
关于所需的布局! 但是,每当我在 id=ripple 的相对布局上注册任何点击侦听器时,它都会停止显示波纹效果!
我正在使用 Android 5.0 Lollipop 的 LG G3 上对其进行测试,我希望 Android 版本 19+ 的 Android 设备应该显示涟漪效应。
我必须使用
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
为了显示连锁反应,有人可以帮我找出我做错了什么吗?提前致谢!
【问题讨论】:
-
也试过了,不行
-
我认为问题可能出在您的 com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal 视图上。我将这些项目更改为简单的 TextView,并且使用 android:background="?android:attr/selectableItemBackground" 对列表中的每个项目产生涟漪效果。在 Android 8.0 上测试。
-
在 Android 4.4 上测试 - 无效。我认为它不应该适用于 Android API
-
显然,涟漪效应只适用于 API 21 及更高版本。
标签: android kotlin android-relativelayout ripple