繁体   English   中英

试图在两个文本视图之间放置一个ImageView?

[英]Attempting to place an ImageView between two text views?

我试图在两个文本视图之间放置两个图像视图,但是当我在Android设备上运行该图像时,尝试运行其中一个或两个文本视图时,我的图像要么消失,要么似乎被“裁剪掉”。 有人可以让我知道为什么会这样吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.annagib.rileycard.Main"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fontFamily="cursive"
        android:text="Riley Rayne"
        android:textColor="#000000"
        android:textSize="40sp" />

    <ImageView
        android:id="@+id/rye"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/chomie" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0"
        android:fontFamily="cursive"
        android:text="Poet. Writer. Innovator"
        android:textColor="#000000"
        android:textSize="40sp" />
</LinearLayout>

您应该将所有textViews和imageview的高度和宽度更改为

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

并且textview的大小太大导致问题。 您应该将其大小更改为小。

    android:layout_width="match_parent"
    android:layout_height="match_parent"

负责视图的重叠

另一种方法是赋予元素权重。 并将高度设为0dp

即。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.annagib.rileycard.Main"
tools:showIn="@layout/activity_main">

<TextView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:fontFamily="cursive"
    android:textSize="40sp"
    android:layout_weight="1"
    android:textColor="#000000"
    android:text="Riley Rayne" />

<ImageView
    android:id="@+id/rye"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/chomie"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:fontFamily="cursive"
    android:layout_weight="1"
    android:textSize="40sp"
    android:textColor="#000000"
    android:text="Poet. Writer. Innovator" />

尝试这个,

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/content_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="3"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:fontFamily="cursive"
            android:text="Riley Rayne"
            android:textColor="#000000"
            android:textSize="40sp" />

        <ImageView
            android:id="@+id/rye"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:src="@drawable/chomie"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:fontFamily="cursive"
            android:text="Poet. Writer. Innovator"
            android:textColor="#000000"
            android:textSize="40sp" />
    </LinearLayout>

暂无
暂无

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

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