0

我試圖將textview定位在用作背景圖像的imageview上。我的問題是Android根據textview文本的長度來計算位置,所以當我將它定位到某個文本時,更長的文本將它再次推出。這是我想要實現的。大黑的事情是我寧願不切斷的一張照片,以便我可以定位這兩個文本瀏覽器(紅色)。我的問題是textview不在任何「android」位置,即任何東西的中心/左/右。通過ImageView定位的Android TextView

enter image description here

+3

在此處張貼您的代碼您嘗試過什麼? – Mahesh

回答

0

可以在垂直的LinearLayout包裝你TextViews。 要在中間(左側或中間的右側)移動此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>