【问题标题】:When we keep two images only one image is shown Android当我们保留两张图片时,Android 只显示一张图片
【发布时间】:2020-05-31 21:24:11
【问题描述】:

我实际上需要解决这个问题,我做了一个活动,我拍摄了两张不同比例的不同图像,当我将两张图像放入其中时,只有一张显示为什么我已经做了一些修复,它们是 android:adjustViewBonds =true 等等,但它不起作用,我使用的是 URI 而不是 Bitmap 任何建议如何修复我做了所有可用的方法 上面是 xml 文件,您可以在约束布局中看到两个图像,当我保持任何图像的比例时,图像 1 的比例为 1:1,图像 2 的比例为 13:3 或类似的东西 所有这一切都不起作用只有一张图像显示任何建议如何使它工作谢谢 谢谢...任何问题请询问:)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="600dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/hgfgfh"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@color/common_google_signin_btn_text_dark_default"
            android:gravity="center"
            android:maxLines="1"
            android:textSize="23sp"
            android:textAlignment="center"
            android:textColor="#000000" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="57dp"
            android:orientation="horizontal">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/fdgfdg"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_margin="10dp"/>

            <TextView
                android:layout_width="172dp"
                android:layout_height="31dp"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="8dp"
                android:text="ghfhgf"
                android:textColor="#000000"
                android:textSize="16sp" />

            <ImageView
                android:id="@+id/textView2"
                android:layout_width="37dp"
                android:layout_height="32dp"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="70dp"
                android:src="@drawable/moreitems_foreground" />


        </LinearLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/image1"
                android:layout_width="198dp"
                android:layout_height="302dp"
                android:layout_centerInParent="true"
                android:adjustViewBounds="true"
                android:maxWidth="39dip"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.5"

                app:layout_constraintTop_toTopOf="parent" />

            <ImageView
                android:id="@+id/image2"
                android:layout_width="198dp"
                android:layout_height="302dp"
                android:adjustViewBounds="true"
                android:maxWidth="39dip"
                android:layout_centerInParent="true"

                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:padding="8dp">

            <ImageView
                android:layout_width="38dp"
                android:layout_height="33dp"
                android:id="@+id/view"
                android:background="@drawable/border"
                android:src="@drawable/view_v_foreground" />

            <Button
                android:id="@+id/like"
                android:layout_width="35dp"
                android:layout_height="36dp"
                android:layout_marginStart="43dp"
                android:background="@drawable/ic_fd_foreground"
                android:backgroundTint="@color/blue"
                android:focusedByDefault="true" />


            <ImageView
                android:id="@+id/save"
                android:layout_width="36dp"
                android:layout_height="32dp"
                android:layout_alignParentEnd="true"
                android:src="@drawable/pump" />

        </RelativeLayout>



        <TextView
            android:id="@+id/sdfsdf"
            android:layout_width="411dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="1dp"
            android:text="Vsdfs"
            android:textColor="@color/blue" />

        <ImageView
            android:layout_width="36dp"
            android:layout_height="33dp"
            android:layout_marginTop="8dp"
            android:src="@drawable/ic_rfgfdrt_foreground" />

    </LinearLayout>

</RelativeLayout>

【问题讨论】:

    标签: java android xml kotlin layout


    【解决方案1】:

    正如我在您的 xml 视图中看到的,您有一些错误。在 id=@+id/image1 的 ImageView 中,您应该替换

        app:layout_constraintStart_toEndOf="@+id/gfdfdg"
    

        app:layout_constraintStart_toEndOf="@+id/image2"
    

    在 id=@+id/image2 的 ImageView 中你应该替换

        app:layout_constraintEnd_toStartOf="@+id/dfgdfg"
    

        app:layout_constraintEnd_toStartOf="@+id/image1"
    

    试试看,让我知道它是否适用于替代品。

    编辑> 为 image1 和 image2 设置了这个替换

        android:layout_width="0dp"
    

    【讨论】:

    • 这位先生是否根本没有工作,先生,当我粘贴代码时,我没有解决这些问题,现在所有这些问题都已修复,它仍然没有任何建议,为什么请忽略实际代码中的名称错误,他们已修复先生
    • 请查看编辑后的答案。另外,您如何在 imageViews 上设置照片,您是否以编程方式添加照片?
    猜你喜欢
    • 2019-08-15
    • 1970-01-01
    • 2021-12-14
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多