1

我需要設置一個TextView我從波紋管XML使用照片的確切具體的一部分,但我設置的所有尺寸都是手工的,我需要是動態的,對於不同尺寸的手機:android - 設置一個TextView完全特定的照片部分?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/list_back" /> 

    <TextView 
     android:id="@+id/CallCenter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/background_dark" 
     android:textStyle="bold" /> 
</RelativeLayout> 

enter image description here

回答

0

我解決我的問題:

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="fitXY" 
    android:src="@drawable/list_back" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <View 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <TextView 
     android:id="@+id/CallCenter" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:paddingLeft="5dp" 
     android:paddingRight="15dp" 
     android:layout_weight="3" 
     android:textColor="@android:color/background_dark" 
     android:textStyle="bold" /> 
</LinearLayout> 

0

有無你嘗試了frameLayout?重力設置爲right | top,如果你需要使用RelativeLayout爲根,你可以使用layout_alignParentX性能應該每個設備

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/CallCenter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="test" 
     android:textSize="20sp" 
     android:textColor="@android:color/background_dark" 
     android:textStyle="bold" 
     android:layout_gravity="right|top" /> 

</FrameLayout> 
+0

可誰不喜歡我的回答人爲什麼至少告訴我? –

0

上工作。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/list_back" /> 

    <TextView 
     android:id="@+id/CallCenter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:textColor="@android:color/background_dark" 
     android:textStyle="bold" /> 
</RelativeLayout> 

但是,如果你不需要,我推薦使用FrameLayout爲根,以避免RelativeLayoutinvalidate()兩個人通話。

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/CallCenter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right|end" 
     android:text="test" 
     android:textSize="20sp" 
     android:textColor="@android:color/background_dark" 
     android:textStyle="bold" /> 
</FrameLayout> 
相關問題