Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to use tools with include layout

How do I use tools:

xmlns:tools="http://schemas.android.com/tools"

With <include>?

I have a layout A that I use tools to populate all the text fields with test data. And I have layout B that use include to copy layout A in to it. How ever when I do that I do not see the test data of A.

How can I see the test data of A included in B?

*Both layouts have xmlns:tools="http://schemas.android.com/tools, I even pushed it to layout tag.

like image 438
Ilya Gazman Avatar asked May 29 '14 21:05

Ilya Gazman


People also ask

What is include in Android layout?

To efficiently reuse complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.

Can one activity have multiple layouts?

You can use as many layouts as possible for a single activity but obviously not simultaneously. You can use something like: if (Case_A) setContentView(R. layout.

Which method is used to access a view element of a layout?

Value for android:idTextView textView = findViewById(R. id. nameTextbox); This code returns the TextView object.

What is attr in Android?

attr/ references to attributes. Attributes are values specified in an app's theme. The attributes in your example are all values specified in the themes provided by the support library. Android also has its very own attributes which can be used with ? android:attr/ .


1 Answers

Check this link, Android tools attributes. It should give you an idea as to how to use the tools attributes. Specifically look at the tools:showIn attribute. It basically allows you to render layout_A in layout_B, in which layout_B has <include layout="@layout/layout_A"/> somewhere in the xml.

Here's an example:

layout_A

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:showIn="@layout/layout_B"
    >

<!-- Your layout code goes here -->

</RelativeLayout>

layout_B

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

<include layout="@layout/layout_A"/>

<!-- Your layout code goes here -->

</RelativeLayout>
like image 129
Alan Caceres Avatar answered Sep 21 '22 12:09

Alan Caceres