Imageview在另一个imageview上

时间:2015-09-25 13:32:37

标签: android

enter image description here

我想以编程方式安排两张图片视图,如图所示。一个是个人资料照片,一个是蓝色圆圈的白色铅笔。

这就是我设置主要资料图片的宽度和高度的方式

int px = metrics.heightPixels / 4;
profilePic = (ImageView)findViewById(R.id.profilePic);
profilePic.getLayoutParams().width = px;
profilePic.getLayoutParams().height = px;

如果我在xml中执行此操作,则会在不同的屏幕尺寸中产生问题。 如何以编程方式实现此目的?

2 个答案:

答案 0 :(得分:1)

将两个imageview放在relativelayout中。使图像成为圆形,并将relativelayout中的小图像视图与底部|布局重力对齐。

答案 1 :(得分:0)

尝试以下,

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

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_marginTop="100dp"
        android:background="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="-20dp"
        android:background="@drawable/ic_launcher" />

</LinearLayout>

这里最主要的是给-20这样的浮动边距很重要。