简体   繁体   中英

how to include a view created in a xml file on my main layout

I want to create a grid of images with text right below the images.

I created in a xml file a image_text item which basically is a linearlayout with and imageview and a textview right below.

I created a tablelayout and I want to add my custom image_text.xml to the table row. But I dont know how to reference my xml file inside. If I use the include statament, how do I pass the image id and text to my item_text.xml?

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="1"
android:padding="@dimen/inner_layout_horizontal_padding"
android:background="@drawable/base_bg_section">

<TableRow>

</TableRow>

Hope that this make sense and you can help me. any help will be greatly appreciated.

It isn't quite that easy I'm afraid. You will either have to duplicate the image and text layout for each of your items, or add them programmatically and set the image and text in code, or create a custom control that uses your layout and then make the custom control have support for setting the image and text through xml. It's possible, but not trivial.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM