First: What am I trying to do? A: I'm trying to do a basic layout reshuffle when the orientation changes without using any .java code of my own.
Here's my activity_main.xml:
<LinearLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
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 a strings.xml file in both /values-land and /values-port, here's port for an 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 the emulator, but when I send this to my phone, the app force closes on inflation with the following errors:
android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
Caused by: java.lang.NumberFormatException: Invalid int: "vertical"
I assume this is because however its retrieving the resource, the wrong type is being returned. But I'm not sure why or how to get around it. Two hours of googling hasn't been much help.
Just another note: If I hard-code the orientation to vertical, it then fails saying that my first ImageView has no layout_width, so I'm pretty sure I'm at least on the right track.
Am I being too much of a simpleton here in hoping to accomplish what I'm after this easily? Any help appreciated. I'm using the latest Android Studio, and my minSDK is 14. All my main .java file does at this point is the standard inflate, this proof of concept is all I've tried to do so far:
setContentView(R.layout.activity_main);
Thanks in advance!
Pic (linked, boo, no rep) of the emulator working fine:
Aucun commentaire:
Enregistrer un commentaire