简体   繁体   English

用imageview线性布局覆盖textview

[英]Overlaying textview with imageview linear layout

I've got a few linear layouts stacked on top of each other, the centre one has an imageview. 我有一些线性布局相互叠放,中间的一个有imageview。 I'm trying to get a textview on top of the imageview in the centre however I'm having trouble. 我正在尝试在中间的imageview顶部获取textview,但是遇到了麻烦。 I've tried with relative layout however it messes up all my other layouts. 我尝试了相对布局,但是它弄乱了我所有其他布局。 Any simple solutions to this? 有什么简单的解决方案吗? EDIT ---- 编辑----

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

I'm trying to get the text view on top of the id/picPreview image view 我正在尝试使文本视图位于id / picPreview图像视图之上

LinearLayout is designed to place layouts/views in a row (linearly). LinearLayout旨在将布局/视图连续(线性)放置。

One solution would be something like this: 一种解决方案是这样的:

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

Why not just use a TextView in place of the centered ImageView and then set the background of the text be the solid color that you are currently using? 为什么不只使用TextView代替居中的ImageView,然后将文本的背景设置为当前使用的纯色? Eg. 例如。

<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