gpt4 book ai didi

android - 图片预览太长

转载 作者:行者123 更新时间:2023-11-30 03:11:45 25 4
gpt4 key购买 nike

我正在尝试使用相机点击图像并将其显示在我的 fragment 中。这是我的代码:

fragment 图片

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

<AutoCompleteTextView
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:background="@color/translucent_grey"
android:ems="10"
android:hint="@string/hint_location"
android:inputType="text"
android:textSize="14sp" >

<requestFocus />
</AutoCompleteTextView>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/snap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/image"
android:layout_alignParentRight="true"
android:layout_marginBottom="108dp"
android:layout_marginRight="160dp"
android:background="@color/white"
android:src="@drawable/camera" />

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:adjustViewBounds="true"
android:orientation="horizontal" />
</RelativeLayout>

<FrameLayout
android:id="@+id/datetime_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="2dp" />
<FrameLayout
android:id="@+id/eventDetails_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp" />

</LinearLayout>
</ScrollView>

ImageFragment.java

@SuppressLint("NewApi")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
ContentResolver cr = getActivity().getContentResolver();
try {
cr.notifyChange(imageUri, null);
File imageFile = new File(tempPhoto.getAbsolutePath());


} catch (Exception e) {
e.printStackTrace();
}

Bitmap photo=null;
if (resultCode == Activity.RESULT_OK) {
try {
photo = android.provider.MediaStore.Images.Media.getBitmap(cr, Uri.fromFile(tempPhoto));
//image.setImageBitmap(photo);
Drawable drawable = new BitmapDrawable(getResources(), photo);
image.setImageDrawable(drawable);
//image.setScaleType(ScaleType.FIT_CENTER);
image.setScaleType(ScaleType.FIT_XY);
} catch (FileNotFoundException e) {

e.printStackTrace();
} catch (Exception e) {

e.printStackTrace();
}
}
}

尽管遵循了此线程上的建议,但我的图像仍被拉伸(stretch),如下所示: enter image description here

你知道我做的有什么问题吗?

最佳答案

将此添加到 imageview 工作:

android:minHeight="120dp" 
android:minWidth="180dp"
android:maxWidth="420dp"
android:maxHeight="680dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

关于android - 图片预览太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20832827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com