que*_*ion 2 android textview android-layout android-imageview
我在ImageView中显示全屏图像,我试图在ImageView的屏幕中心添加TextView,但TextView没有显示.
我试过了:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/splash_imageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dip"
android:background="#AA000000"
android:padding="12dip"
android:text="SomeText"
android:textColor="#ffffffff" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
您可以使用FrameLayout,AbsoluteLayout(已弃用)或RelativeLayout(最常见的).使用RelativeLayout中心的一个例子android:layout_centerInParent="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/splash_imageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dip"
android:layout_centerInParent="true"
android:background="#AA000000"
android:padding="12dip"
android:text="SomeText"
android:textColor="#ffffffff" />
</RelativeLayour>
Run Code Online (Sandbox Code Playgroud)
drawing views与XML中的顺序相同,因此ImageView将首先绘制,然后TextView记住android:elevationxml属性和view.bringToFront()Java方法
| 归档时间: |
|
| 查看次数: |
21242 次 |
| 最近记录: |