开发者

Android: TextView margin bottom

I have an image with a square... In layout I want to set text inside square, so I set property margin bottom 100dp to 'TextView' and in HDPI phone my text is in square. That's cool. But when I r开发者_StackOverflowun my app on MDPI device Text looks a little bit higher then it should be.

And its understandable, because MDPI and HDPI has different resolutions...So how to be ? How to set text so, that its looks proportional on both devices?


Why don't you just wrap the image and the text inside a FrameLayout, and give the TextView a layout_gravity="center" attribute? With your current method, different aspect ratios will give you different positioning.


You can use FrameLayout in this case. Here is a simple example:

<FrameLayout 
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" 
    android:background="#ff0000">

    <ImageView
        android:layout_height="100dp"
        android:layout_width="100dp"            
        android:background="#00ff00"
        android:src="@drawable/icon"
        android:scaleType="fitXY" />

    <TextView 
        android:layout_height="100dp"
        android:layout_width="100dp"            
        android:gravity="center" 
        android:text="This is text"
        android:textColor="#0000ff"/>

</FrameLayout>

Android: TextView margin bottom

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜