1

I m not satisfied with the result of my layout whenever I test it in landscape mode on different screen size devices. In portrait I like the margin of the textview. Since my current image size of the imageview will not fill the full width of some devices out there in landscape there is some whitespace left and right to it, which is fine. however, the margin of the textview should also take this whitespace into account and add it somehow. I know i can create a different xml style for landscape modes, but any fixed margin wont help here... thanks for any help in advance

enter image description here

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:scaleType="fitStart"
    android:adjustViewBounds="true"
    android:src="@drawable/start1_8" />

<TextView
    style="@style/DescriptionTitle"
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/imageView1"
    android:text="Test Titelzeile"   />

<style name="DescriptionTitle" parent="@android:style/TextAppearance">
    <item name="android:textColor">#0099cc</item>
    <item name="android:textStyle">bold|italic</item>
    <item name="android:textSize">20sp</item>
    <item name="android:layout_gravity">center_vertical|left</item>
    <item name="android:gravity">top|left</item>
    <item name="android:layout_marginLeft">15dp</item>
    <item name="android:layout_marginRight">15dp</item>
    <item name="android:layout_marginTop">5dp</item>

</style>
4

2 回答 2

3

I would put it in a Relative Layout like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:gravity="center_horizontal"
              android:layout_height="match_parent">
    <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:scaleType="fitStart"
            android:adjustViewBounds="true"
            android:src="@drawable/Untitled-1" />
    <TextView
            style="@style/DescriptionTitle"
            android:id="@+id/textView1"
            android:layout_alignLeft="@id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/imageView1"
            android:text="Test Titelzeile"   />
</RelativeLayout>

Then it will be in the correct relative position regardless of view size or orientation.

于 2013-03-31T01:36:53.127 回答
0

resize the view in runtime and use(like screenwidth/4 ) a ratio hor image width and position.

use LayoutParams to do it.

于 2013-03-31T00:51:30.950 回答