java - Getting layout.xml orientation/height/width properties from resource XML file -
first: trying do? a: i'm trying basic layout reshuffle when orientation changes without using .java code of own.
here's activity_main.xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/black" android:paddingleft="0dp" android:paddingright="0dp" android:paddingtop="0dp" android:paddingbottom="0dp" android:orientation="@string/wrapper_orientation" tools:context=".mainactivity"> <imageview android:layout_width="@string/image_width" android:layout_height="@string/image_height" android:layout_weight="@string/image_weight" android:background="@drawable/customborder" /> <linearlayout android:layout_width="@string/content_width" android:layout_height="@string/content_height" android:layout_weight="@string/content_weight" android:orientation="vertical"> <textview android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight=".5" android:background="@drawable/customborder" /> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight=".5" android:background="@drawable/customborder"> </relativelayout> </linearlayout> </linearlayout> i have strings.xml file in both /values-land , /values-port, here's port example:
<resources> <string name="wrapper_orientation">vertical</string> <string name="image_width">fill_parent</string> <string name="image_height">0dp</string> <string name="image_weight">.45</string> <string name="content_width">fill_parent</string> <string name="content_height">0dp</string> <string name="content_weight">.55</string> </resources> this works fine in emulator, when send phone, app force closes on inflation following errors:
android.view.inflateexception: binary xml file line #1: error inflating class <unknown> caused by: java.lang.numberformatexception: invalid int: "vertical" i assume because retrieving resource, wrong type being returned. i'm not sure why or how around it. 2 hours of googling hasn't been help.
just note: if hard-code orientation vertical, fails saying first imageview has no layout_width, i'm pretty sure i'm @ least on right track.
am being of simpleton here in hoping accomplish i'm after easily? appreciated. i'm using latest android studio, , minsdk 14. main .java file @ point standard inflate, proof of concept i've tried far:
setcontentview(r.layout.activity_main); thanks in advance!
pic (linked, boo, no rep) of emulator working fine:
in xml, vertical , horizontal orientation designations not strings, integer constants pre defined. taking incorrect approach problem. better option use multiple layout files defined in resource directories appropriate qualifiers. have layout-port , layout-land folder in res layout xml file defined same name in each, the appropriate changes layout each orientation. can read more resource qualifiers here:
Comments
Post a Comment