gpt4 book ai didi

android - 单击 ImageView 时图像不全屏显示

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

我想在单击 imageView 时全屏显示我的 bitmap 图像(从画廊或捕获的图像中选择)。

 imageView .setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(zoomOut) {
Toast.makeText(getApplicationContext(), "NORMAL SIZE!", Toast.LENGTH_LONG).show();
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
imageView.setAdjustViewBounds(true);
zoomOut =false;
}else{
Toast.makeText(getApplicationContext(), "FULLSCREEN!", Toast.LENGTH_LONG).show();
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
zoomOut = true;
}
}
});

这是我的 xml( Activity B)

   <?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/dark_blue"
android:weightSum="1">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Enter Claims Information"
android:id="@+id/textViewClaims"
android:paddingTop="30sp"
android:textSize="20dp"
android:paddingLeft="15sp"
android:textColor="@color/white"
android:layout_weight="0.05" />

<View
android:layout_marginLeft="10dp"
android:layout_width="340sp"
android:layout_height="2dp"
android:background="#c0c0c0"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Claims Type : "
android:paddingTop="20sp"
android:paddingLeft="15sp"
android:textSize="17dp"
android:textColor="@color/white"
android:id="@+id/textViewClaimsType"
android:layout_weight="0.05" />

<Spinner
android:layout_width="340dp"
android:layout_marginLeft="10dp"
android:background="@color/light_gray"
android:layout_height="48dp"
android:id="@+id/spinner1"
android:spinnerMode="dropdown" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Claims Amount :"
android:paddingTop="20sp"
android:paddingLeft="15sp"
android:textSize="17dp"
android:textColor="@color/white"
android:id="@+id/textViewAmount"
android:layout_weight="0.05" />

<EditText
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:background="@drawable/round_corner_square"
android:id="@+id/editTextAmount"
android:hint=" RM "
android:paddingLeft="20dp"
android:layout_weight="0.09" />


<ImageView
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_marginTop="20dp"
android:layout_width="350dp"
android:src="@mipmap/no_image"
android:layout_height="300dp"
android:id="@+id/imageView" />


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add picture"
android:id="@+id/buttonAdd"
android:layout_gravity="center_horizontal"
android:layout_weight="0.05" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Enter Description : "
android:paddingTop="30sp"
android:paddingLeft="15sp"
android:textSize="17dp"
android:textColor="@color/white"
android:id="@+id/textView12"
android:layout_weight="0.05" />

<EditText
android:layout_width="340dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/round_corner_square"
android:layout_weight="0.12"
android:paddingLeft="20dp"
android:paddingBottom="80dp"
android:layout_x="14dp"
android:layout_y="146dp"
android:id="@+id/textDescription" />

<Button
android:layout_width="159dp"
android:layout_height="wrap_content"
android:text="save"
android:layout_marginTop="20dp"
android:id="@+id/buttonSave"
android:layout_gravity="center_horizontal"
android:layout_weight="0.05" />


</LinearLayout>
</ScrollView>

Activity B

点击前

enter image description here

点击后

enter image description here

再次点击缩小

enter image description here

最佳答案

使用以下代码编辑您的代码

TextView mTextViewClaims = (TextView) findViewById(R.id.textViewClaims);
TextView mTextViewClaimsType = (TextView) findViewById(R.id.textViewClaimsType);
TextView mTextViewAmount = (TextView) findViewById(R.id.textViewAmount);
TextView mTextView12 = (TextView) findViewById(R.id.textView12);

EditText mEditTextAmount = (EditText) findViewById(R.id.editTextAmount);
EditText mTextDescription = (EditText) findViewById(R.id.textDescription);

Button mButtonAdd = (Button) findViewById(R.id.buttonAdd);
Button mButtonSave = (Button) findViewById(R.id.buttonSave);

imageView .setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(zoomOut) {
Toast.makeText(getApplicationContext(), "NORMAL SIZE!", Toast.LENGTH_LONG).show();

float scale = getContext().getResources().getDisplayMetrics().density;
imageView.setLayoutParams(new LinearLayout.LayoutParams((int)(350 * scale + 0.5f) , (int)(300 * scale + 0.5f)));
imageView.setAdjustViewBounds(true);

mTextViewClaims.setVisibility(View.VISIBLE);
mTextViewClaimsType.setVisibility(View.VISIBLE);
mTextViewAmount.setVisibility(View.VISIBLE);
mTextView12.setVisibility(View.VISIBLE);
mEditTextAmount.setVisibility(View.VISIBLE);
mTextDescription.setVisibility(View.VISIBLE);
mButtonAdd.setVisibility(View.VISIBLE);
mButtonSave.setVisibility(View.VISIBLE);

zoomOut =false;
}else{
Toast.makeText(getApplicationContext(), "FULLSCREEN!", Toast.LENGTH_LONG).show();
float scaleHeigth = getApplicationContext().getResources().getDisplayMetrics().heightPixels;
float scaleWidth = getApplicationContext().getResources().getDisplayMetrics().widthPixels;
imageView.setLayoutParams(new LinearLayout.LayoutParams((int)scaleWidth , (int)scaleHeigth));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);

mTextViewClaims.setVisibility(View.GONE);
mTextViewClaimsType.setVisibility(View.GONE);
mTextViewAmount.setVisibility(View.GONE);
mTextView12.setVisibility(View.GONE);
mEditTextAmount.setVisibility(View.GONE);
mTextDescription.setVisibility(View.GONE);
mButtonAdd.setVisibility(View.GONE);
mButtonSave.setVisibility(View.GONE);

zoomOut = true;
}
}
});

关于android - 单击 ImageView 时图像不全屏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34230107/

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