繁体   English   中英

用imageview线性布局覆盖textview

[英]Overlaying textview with imageview linear layout

我有一些线性布局相互叠放,中间的一个有imageview。 我正在尝试在中间的imageview顶部获取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" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="horizontal"
    android:paddingLeft="50dp"
    android:paddingRight="50dp" >

    <ImageButton
        android:id="@+id/btnBck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:id="@+id/btnHome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

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

    <ImageView
        android:id="@+id/picPreview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        android:contentDescription="@string/imageDesc"
        android:src="@null" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="horizontal"
    android:paddingLeft="50dp"
    android:paddingRight="50dp" >

    <ImageButton
        android:id="@+id/btnAccept"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:id="@+id/btnDecline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

</LinearLayout>

我正在尝试使文本视图位于id / picPreview图像视图之上

LinearLayout旨在将布局/视图连续(线性)放置。

一种解决方案是这样的:

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


    <ImageView
        android:id="@+id/picPreview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        android:contentDescription="@string/imageDesc"
        android:layout_centerInParent="true"
        android:src="@null" />
    <TextView
        android:id="@+id/picPreviewLbl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:text="Overlay" />

</RelativeLayout>
</LinearLayout>

为什么不只使用TextView代替居中的ImageView,然后将文本的背景设置为当前使用的纯色? 例如。

<TextView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:text="Sample Text" ... />

暂无
暂无

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

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