Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet168/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   164   165   166   167   168   169   170   171   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

199
CHAPTER 9: User Interface
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="8dip"
android:contentDescription="TODO"
android:src="@android:drawable/star_big_on" />
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/icon"
android:singleLine="true"
android:text="Description"
android:textSize="12sp" />
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/icon"
android:gravity="center_vertical"
android:text="Example application"
android:textSize="16sp" />

As stated earlier, you could also omit this step and define an item’s layout solely from inside 
the code! Next we provide an adapter. In Kotlin this could be as easy as follows:
class MyAdapter(val myDataset:Array) :
RecyclerView.Adapter
() {
companion object {
class ViewHolder(val v:RelativeLayout) :
RecyclerView.ViewHolder(v)
}
override
fun onCreateViewHolder(parent:ViewGroup,
viewType:Int) : ViewHolder {
val v = LayoutInflater.from(parent.context)
.inflate(R.layout.item, parent, false)
as RelativeLayout
return ViewHolder(v)
}



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   164   165   166   167   168   169   170   171   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling