繁体   English   中英

Android TextView超过ImageView定位

[英]Android TextView over ImageView positioning

我试图将textview放在用作背景图像的imageview上。 我的问题是Android根据textview的文本长度计算位置,因此当我将其与特定文本一起放置时,较长的文本会再次将其推出位置。 这是我想要实现的。 黑色的大东西是一张图片,我不想剪切,只是我可以将这两个文本视图(红色)定位。 我的问题是textviews arent不在任何“ android”位置,即任何东西的中心/左/右。

在此处输入图片说明

您可以将TextViews包装在垂直的LinearLayout中。 要在中间(中间的左侧或右侧)移动此LinearLayout,请使用具有空视图和android:layout_weight属性的水平LinearLayout。 例如:

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical"
android:layout_width="match_parent" 
android:layout_height="match_parent"

<ImageView
            android:layout_width="match_parent" 
            android:src="@drawable/your_image" 
            android:layout_height="match_parent"/>

<LinearLayout
            android:orientation="horizontal" 
            android:layout_width="match_parent" 
            android:layout_alignParentBottom="true" 
            android:layout_marginBottom="50dp" 
            android:layout_height="wrap_content">
<View
                android:layout_width="0dp" 
                android:layout_height="0dp" 
                android:layout_weight="1.2"/>
<LinearLayout
                android:orientation="vertical" 
                android:layout_width="0dp" 
                android:layout_weight="1" 
                android:layout_height="wrap_content">
<TextView
                    android:id="@+id/text_view" 
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content" 
                    android:text="Short text"/>
<TextView
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content" 
                    android:text="Looooooooooooooooooooooong text"/>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM