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

时间:2017-02-20 03:42:28

标签: android xml user-interface

我试图在两个文字视图之间放置两个图像视图,但我的图像消失或者似乎被裁剪掉了#39;当我尝试运行它时,我在我的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>

2 个答案:

答案 0 :(得分:0)

您应该将所有textViews和图片视图的高度和宽度更改为

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

并且textview大小太大而导致问题。你应该把它的大小改成小。和atrribs一样

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

答案 1 :(得分:0)

试试这个,

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