Android sdk 18 TextView 重力不能垂直工作

Android sdk 18 TextView gravity doesn#39;t work vertically(Android sdk 18 TextView 重力不能垂直工作)
本文介绍了Android sdk 18 TextView 重力不能垂直工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

SDK 18 有问题.我的文本视图的重力不能垂直工作.但它适用于 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 上,但边距不适用.目前我将项目留给 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.

这篇关于Android sdk 18 TextView 重力不能垂直工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Java android: appending a newline using TextView(Java android:使用 TextView 添加换行符)
How to create simple Android TextView and display text on it using java code?(如何使用 java 代码创建简单的 Android TextView 并在其上显示文本?)
Add opaque quot;shadowquot; (outline) to Android TextView(添加不透明的“阴影(大纲)到 Android TextView)
Android: Creating a Circular TextView?(Android:创建一个圆形 TextView?)
Android - set TextView TextStyle programmatically?(Android - 以编程方式设置 TextView TextStyle?)
Android Horizontal LinearLayout - Wrap Elements(Android 水平线性布局 - 包装元素)