Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use layout_width using resource file?

There are a activity what I want to fill the screen in a phone and pop up(dialog) for a tablet.

I thought I make a layout file like this,

<LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="@dimen/main_layout_width"   android:layout_height="match_parent"> 

and externalize the value of width as

in values/dimens.xml

<dimen name="tutorial_width">match_parent</dimen> 

in values-xlarge/dimens.xml

<dimen name="tutorial_width">320dp</dimen> 

But I can't representation 'match_parent' as dimen element. Any help? Thanks!

like image 977
Shakra Avatar asked Jul 28 '11 12:07

Shakra


People also ask

What is id value resource?

android:id. Resource ID. A unique resource name for the element, which you can use to obtain a reference to the ViewGroup from your application. See more about the value for android:id below.

How do I insert one XML file into another Android?

Probably you will have to set within the include tag the properties that sets where it has to be placed: android:layout_above, android:layout_toLeftOf, etc... Use fill_parent instead. I pasted my code and I am working with honeycomb, thats why I was using match_parent. But it should work with fill_parent.

What are Android resources?

In Android, a resource is a localized text string, bitmap, layout, or other small piece of noncode information that your app needs. At build time, all resources get compiled into your application. The resources locates inside res directory of your app.

What is the XML element for adding a layout defined in another layout file?

To efficiently re-use complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout.


1 Answers

The best way I found: - instead of "match_parent" and "fill_parent" write "-1dp" - instead of "wrap_content" write "-2dp"

like image 136
pjanecze Avatar answered Sep 19 '22 23:09

pjanecze