問(wèn)題描述
SDK 18 有問(wèn)題.我的文本視圖的重力不能垂直工作.但它適用于 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.
圖片和代碼:
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 為黑色背景android:background="#000000"
with black background for textview android:background="#000000"
如果有人有想法.我嘗試用 match_parent 更改 wrap_content.
If someone have an idea. I have try to change wrap_content with match_parent.
唯一有效的是android:layout_height="@dimen/entete.size.h" 在 TextView 上,但邊距不適用.目前我將項(xiàng)目留給 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.
推薦答案
問(wèn)題是 RelativLayout 作為 listview 項(xiàng)的根布局.如果您在 RelativeLayout 周?chē)胖靡粋€(gè) LinearLayout,它也適用于 targetSdk = 19.GridView 也會(huì)出現(xiàn)同樣的問(wèn)題.
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>
這不是一個(gè)很好的解決方法 - 但我猜比將 targetSdk = 17 更好.
This is not really a nice workaround - but better than put targetSdk = 17 I guess.
這篇關(guān)于Android sdk 18 TextView 重力不能垂直工作的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!