【问题标题】:Android FrameLayout Views Overlapping not WorkingAndroid FrameLayout视图重叠不起作用
【发布时间】:2019-05-24 15:14:58
【问题描述】:

我有以下布局,我需要使用 FrameLayout 将最喜欢的图像放置在 itemImage 的右上角

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ItemDetails"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="20dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/itemdimage"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:scaleType="fitEnd"
                tools:srcCompat="@mipmap/ic_launcher"
                />

            <ImageView
                android:id="@+id/favorite"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="end"
                android:layout_margin="10dp"
                tools:srcCompat="@mipmap/ic_launcher_round"
                android:elevation="10dp"/>

        </FrameLayout>

但最喜欢的图像永远不会显示??我的布局有什么问题

任何帮助将不胜感激

【问题讨论】:

  • 布局对我来说似乎没问题,图像在我的 Android Studio 的右上角。也许问题出在您以编程方式更改图像时。
  • @RomainGoutte-Fangeas 我在活动代码中没有任何改变!

标签: android android-layout


【解决方案1】:

也许这种布局会起作用。我将tools:srcCompat 更改为android:srctools: 属性仅在 AndroidStudio 中可见,它们已从构建中删除。

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="20dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/itemdimage"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:scaleType="fitEnd"
                android:src="@mipmap/ic_launcher"/>

            <ImageView
                android:id="@+id/favorite"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="end"
                android:layout_margin="10dp"
                android:elevation="10dp"
                android:src="@mipmap/ic_launcher_round" />

        </FrameLayout>
    </LinearLayout>
</ScrollView>

结果是这样的:

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 1970-01-01
    相关资源
    最近更新 更多