android - ImageView 对齐问题

标签 android android-layout imageview android-relativelayout

我想用 ImageView 和相对布局实现我的布局,如图所示。

enter image description here

我尝试使用此代码但不起作用。

<RelativeLayout
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textview_ratting"
    android:layout_margin="5dp">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/imageView"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_centerHorizontal="true"
        android:src="@drawable/icon"/>
</RelativeLayout>

最佳答案

这对我有用...提供负 paddingTop 等于 imageview 大小的一半。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="70dp"
            android:background="@color/colorAccent" />
        <ImageView
            android:id="@+id/widget_title_icon"
            android:paddingTop="-70dp"
            android:layout_width="140dp"
            android:layout_height="140dp"
            android:layout_gravity="top|center_horizontal"
            android:adjustViewBounds="true"
            android:contentDescription="@string/action_settings"
            android:scaleType="fitStart"
            android:src="@mipmap/ic_launcher" />
</FrameLayout>

this is the image screenshot

关于android - ImageView 对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41469410/

相关文章:

java - 访问 .jar API 函数 - 错误 : Cannot make a static reference to the non-static method

android - 更改自定义 Toast 中的文本和图标?

android - 如何在 android studio 设计预览中隐藏黑色菜单栏?

android - 使用合并标记时,复合 View 不可见

android - ListView 行中的各种项目 - 屏幕截图示例

Android Wear 通知页面操作

java - 缺少 Google Play 游戏服务类

android - (Glide) 从缓存中获取图像(如果存在)

java - Android - 如何在ImageView的右上角添加通知计数器

android - ImageView 在一个 Activity 中显示但不在另一个 Activity 中