【发布时间】:2018-02-06 20:10:59
【问题描述】:
我有一个固定在导航菜单右上角的图像按钮,当您单击它时,您可以从您的 android 库中选择一个图像并将其作为您的头像。
但是,一旦您选择了图片,图片按钮就会变得非常大。
这是按钮最初的样子:Before Choosing avatar
这是选择头像后按钮的样子:After choosing avatar
我在 NavDrawerActivity 类的 onCreate() 方法中插入了这段代码
imgButton = (ImageButton) navigationHeaderView.findViewById(R.id.imageButton1);
imgButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, IMAGE_UPLOAD_REQUEST);
}
});
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), getThumbnail("desiredFilename.png"));
roundedBitmapDrawable.setCircular(true);
imgButton.setImageDrawable(roundedBitmapDrawable);
这是我的 XML:
<ImageButton
android:layout_gravity="right"
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:scaleType="fitXY"
app:srcCompat="@android:drawable/ic_menu_gallery"/>
【问题讨论】:
标签: java android xml android-studio layout