Android SDK中18 TextView的比重不垂直工作比重、工作、SDK、Android

2023-09-08 09:28:22 作者:壿嫱腳哭淇

我与SDK 18 probleme。 我的文本视图的严重性不垂直工作。但它的工作与sdk17。

I have a probleme with the SDK 18. The gravity of my text view doesn't work vertically. But it's working with sdk17.

图片和code:

header_of_listView.xml:

header_of_listView.xml :

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/RelativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/iv_bg"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/entete.size.h"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_centerHorizontal="true"
            android:contentDescription="@string/blank"
            android:scaleType="fitXY"
            android:src="@drawable/cellule_flecher_mise_en_valeur" />

        <TextView
            android:id="@+id/tv_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/iv_bg"
            android:layout_alignLeft="@id/iv_bg"
            android:layout_alignRight="@id/iv_bg"
            android:layout_alignTop="@id/iv_bg"
            android:layout_marginBottom="6dp"
            android:gravity="center"
            android:text="@string/a_remplacer"
            android:textColor="@color/tableviewText"
            android:textSize="18sp"
            android:textStyle="bold" 
            android:layout_centerHorizontal="true"/>

    </RelativeLayout>

AndroidManifest.xml中

AndroidManifest.xml

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

AndroidManifest.xml中

AndroidManifest.xml

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

与黑色背景的TextView 机器人:后台=#000000

with black background for textview android:background="#000000"

如果一个人有一个想法。 我试图改变WRAP_CONTENT与match_parent。

If someone have an idea. I have try to change wrap_content with match_parent.

唯一令工作 机器人:layout_height =@扪/ entete.size.h关于TextView的,但毛利率并不适用。 目前我离开项目SDK 17。

The only thing that work is android:layout_height="@dimen/entete.size.h" on the TextView, but the margin doesn't apply. For the moment I leave the project to SDK 17.

推荐答案

问题是RelativLayout的ListView项的根布局。如果你把周围的RelativeLayout的一个LinearLayout中它的工作原理也与targetSdk = 19。 出现同样的问题与GridView控件。

The problem is the RelativLayout as root layout of the listview item. If your put a LinearLayout around the RelativeLayout it works also with targetSdk = 19. Same problem appears with the GridView.

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

   ... your layout like before

</LinearLayout>

这是不是真的一个很好的解决办法 - 但总比把targetSdk = 17我猜

This is not really a nice workaround - but better than put targetSdk = 17 I guess.