【问题标题】:Position imageview relative to another imageview相对于另一个 imageview 定位 imageview
【发布时间】:2017-02-03 14:06:26
【问题描述】:

我无法在 imageview 的右下角添加水印。

所以,我们的想法是在另一个 imageview(我正在编辑的图像)的底部添加 imageview(水印)。

问题是,我要编辑的照片有不同的尺寸(垂直、水平、大、小)。

这是我所拥有的:

<RelativeLayout
android:id="@+id/relativelayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:mobfox="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:id="@+id/tb_buy"
        android:textSize="18sp"
        android:textStyle="bold"
        android:background="@null"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:textColor="@color/icons"
        android:text="BUY PRO"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:id="@+id/tb_save"
        android:textSize="18sp"
        android:textStyle="bold"
        android:background="@null"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:textColor="@color/icons"
        android:text="SAVE"/>

</android.support.v7.widget.Toolbar>


<FrameLayout
    android:id="@+id/framelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/toolbar"
    android:layout_above="@+id/banner">

    <ImageView
        android:id="@+id/iv_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!--<ImageView-->
        <!--android:id="@+id/iv_watermark"-->
        <!--android:layout_width="wrap_content"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:layout_gravity="bottom|right"-->
        <!--android:alpha="0.7"-->
        <!--android:src="@drawable/watermark"/>-->

</FrameLayout>

<com.mobfox.sdk.bannerads.Banner
    android:layout_height="50dp"
    android:layout_width="320dp"
    android:id="@+id/banner"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true">
</com.mobfox.sdk.bannerads.Banner>

这会将水印图像视图放在 FrameLayout 的右下角。

在这种情况下,我希望它位于我正在编辑的 imageview 的右下角。

附:我还尝试以编程方式添加它,我认为这是“可行的方法”,但我不知道所有功能和可能的方法。

我尝试了类似的东西

        //#### WATERMARK ####
    ImageView watermark = new ImageView(this);
    watermark.setImageResource(R.drawable.watermark);
    watermark.setBottom(editPhoto.getBottom());
    watermark.setRight(editPhoto.getRight());
    mLayout.addView(watermark);

但这不起作用。它只是在屏幕中心拉伸水印图像视图。

【问题讨论】:

    标签: android xml imageview position watermark


    【解决方案1】:

    您可以通过将FrameLayout 替换为RelativeLayout 来实现这一点,并且父布局的heightwidth 应该是wrap_content

    类似这样的:

    <RelativeLayout
    android:id="@+id/relativelayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:mobfox="http://schemas.android.com/apk/res-auto">
    
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:background="@color/colorPrimary"
        android:minHeight="?attr/actionBarSize">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:id="@+id/tb_buy"
            android:textSize="18sp"
            android:textStyle="bold"
            android:background="@null"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:textColor="@color/icons"
            android:text="BUY PRO"/>
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:id="@+id/tb_save"
            android:textSize="18sp"
            android:textStyle="bold"
            android:background="@null"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:textColor="@color/icons"
            android:text="SAVE"/>
    
    </android.support.v7.widget.Toolbar>
    
    
    <RelativeLayout
        android:id="@+id/framelayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
        android:layout_above="@+id/banner">
    
        <ImageView
            android:id="@+id/iv_photo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    
        <ImageView
            android:id="@+id/iv_watermark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alighRight="@id+/iv_photo"
            android:layout_alighBottom="@id+/iv_photo" 
            android:alpha="0.7"
            android:src="@drawable/watermark"/>
    
    </RelativeLayout>
    
    <com.mobfox.sdk.bannerads.Banner
        android:layout_height="50dp"
        android:layout_width="320dp"
        android:id="@+id/banner"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true">
    </com.mobfox.sdk.bannerads.Banner>
    

    【讨论】:

    • 当我读到你的评论时,我心想,'是的,这应该行得通。'但它没有......这让我更加困惑。我做了你所说的一切,甚至尝试了其他几个选项,但水印图像视图仍然粘在父级的底部而不是编辑后的图像。
    • 你把超级视频的layout_widthlayout_height改成id为framelayout的了吗?
    【解决方案2】:

    用RelativeLayout代替FrameLayout试试:

        <RelativeLayout
        android:id="@+id/rl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
        android:layout_above="@+id/banner">
    
        <ImageView
            android:id="@+id/iv_photo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjsutViewBounds="true"/>
    
        <ImageView
            android:id="@+id/iv_watermark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:alpha="0.7"
            android:layout_alighRight="@id+/iv_photo"
            android:layout_alighBottom="@id+/iv_photo"
            android:src="@drawable/watermark"/>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多