java - 用imageview线性布局覆盖textview

标签 java android eclipse textview imageview

我有几个线性布局彼此堆叠,中间的布局有一个 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>

我试图让 TextView 位于 id/picPreview ImageView 之上

最佳答案

LinearLayout 旨在将布局/ View (线性)放置在一行中。

一个解决方案是这样的:

<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>

关于java - 用imageview线性布局覆盖textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21716176/

相关文章:

java - 使用 eclipse for windows 在 java 中进行套接字流传输

java - 在 Recyclerview 中显示来自具有多个值的 JSONobject 单个字符串的数据

android - 保存在联系人中适用于 Android 10 但不适用于 Android 11

java - 如何让 Eclipse 显示我的类中的 javadoc 而无需在 jar 中包含源代码

Android测试项目找不到app类

java - JFormattedTextField 插入符号在焦点上的位置

java.lang.ClassNotFoundException : org. apache.pdfbox.exceptions.COSVisitorException 异常

android - Android 3.0 中搜索栏的变化

android - CoordinatorLayout、AppBarLayout 和 ToolBar - 工具栏不会滚出屏幕

c - 使用英特尔 aes API 时出错