android - 设置一个 TextView 正好是照片的特定部分?
android - Set a TextView exactly specific part of the photo?
我需要设置一个 TextView,正好是我正在使用的照片的特定部分,来自波纹管 xml 但我设置了所有尺寸手册 我需要为不同尺寸的手机动态设置:
<?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>
您尝试过使用 frameLayout 吗?将重力设置为 right | top
它应该适用于所有设备
<?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>
如果您需要使用 RelativeLayout
作为 root,您可以使用 layout_alignParentX
属性。
<?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
作为 root 以避免从 RelativeLayout
.
重复调用 invalidate()
<?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>
我解决了我的问题:
<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>
我需要设置一个 TextView,正好是我正在使用的照片的特定部分,来自波纹管 xml 但我设置了所有尺寸手册 我需要为不同尺寸的手机动态设置:
<?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>
您尝试过使用 frameLayout 吗?将重力设置为 right | top
它应该适用于所有设备
<?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>
如果您需要使用 RelativeLayout
作为 root,您可以使用 layout_alignParentX
属性。
<?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
作为 root 以避免从 RelativeLayout
.
invalidate()
<?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>
我解决了我的问题:
<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>