开发者

Android, RelativeLayout

I have a background image child inside a relative layout:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerInside"
    android:src="@drawable/game_background_main"
    android:id="@+id/mainBackground"
    />

I then introduce a TextView after this child inside the relative layout:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/mainBackground"
    android:layout_marginTop="14dp"
    android:maxLines="1"
    android:scrollHorizontally="true"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:marqueeRepeatLimit="1"
    android:textColor="@android:color/black"
    android:background="@color/beige"
    android:id="@+id/myText"
    />

Now, on my device at least, the mainBackground image is scaled so that the height is the same as the screen, but the width is then slightly less and so there is a gap on the left and right sides. This is fine.

The problem is the myText text view -- why does its left side start from the left side of the screen开发者_如何学编程 and not the left side of the mainBackground image as instructed?


The ImageView's left side is at the left side of the screen. centerInside only affects the location of the content in the ImageView, not the location of the ImageView.

If you want the ImageView to be centered in the RelativeLayout set android:gravity="CENTER" on the ImageView.


just put
android:layout_toRightOf="@+id/mainBackground" in textview tag & remove
android:layout_alignLeft="@id/mainBackground" from textview tag

hope this might help....

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜