![](/img/trans.png)
[英]Center Gravity for TextView doesn't work on xxhdpi in RelativeLayout
[英]Android sdk 18 TextView gravity doesn't work vertically
我對SDK 18有疑問。我的文本視圖的重力不能垂直工作。 但它正在與sdk17合作。
圖片和代碼:
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中
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
AndroidManifest.xml中
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
用textview android的黑色背景:background =“#000000”
如果有人有想法。 我試着用match_parent改變wrap_content。
唯一可行的是android:layout_height =“@ dimen / entete.size.h”在TextView上,但保證金不適用。 目前我將項目留給SDK 17。
問題是RelativLayout作為listview項的根布局。 如果你在RelativeLayout周圍放置一個LinearLayout,它也可以用於targetSdk = 19. 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更好。
我有同樣的問題,它只發生在Android 19.我的目標api 23,它工作正常。
我發現給textview一個高度可以解決這個問題
就像這樣:
<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"/>
我這樣做了:
<TextView
android:id="@+id/tv_message"
android:layout_width="wrap_content"
android:layout_height="40dp" <!-- this is the key-->
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"/>
由於性能問題,我不想添加另一個線性布局。
刪除android:targetSdkVersion="18"
並運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.