gpt4 book ai didi

android - 让我的图像与其余的 edittext 控件高度相同

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

我有一张图片占据了整个屏幕。我试过增加和减少控件权重,调整最小和最大高度和宽度,但我无法获得与其他控件相同的图像高度。

<TextView
android:id="@+id/header_screenName_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/appBodyDefault"
android:textSize="@dimen/titleFontSize"
android:textColor="@color/white"
android:gravity="left"
android:text="@string/activity_newuser_header_string" />

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:background="@color/yellow"
android:layout_margin="20dp">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/firstName_editText"
android:layout_weight="1"
android:hint="First Name" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/lastName_editText"
android:layout_weight="1"
android:hint="Last Name" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/passwordOne_editText"
android:layout_weight="1"
android:hint="Password" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/passwordTwo_editText"
android:layout_weight="1"
android:hint="Re-type Password" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/email_editText"
android:layout_weight="1"
android:hint="Email" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/btn_profile"
android:clickable="false"
android:adjustViewBounds="true" />
</LinearLayout>
</LinearLayout>

最佳答案

在 android 中以良好的方式缩放图像很难,我使用这种方法是为了图像在 View 中使用整个空间而不会丢失分辨率。(仅在 ImageView 中使用它)

public static void ajustarImageViewToImage(final ImageView iv) {
ViewTreeObserver observer = iv.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//Fazendo o redimensionamento das imagens para de acordo com o VIEW
Drawable drawable = iv.getDrawable();
int ih = drawable.getIntrinsicHeight();
int iw = drawable.getIntrinsicWidth();

int x = ((iv.getWidth() * ih) / iw) + 1;

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, x);
lp.weight = 1;
lp.setMargins(0, 0, 0, 10);
iv.setLayoutParams(lp);
}
});
}

如果您不关心分辨率和比例,请尝试在 XML 的 ImageView 中使用 android:scaleType="fitXY"

关于android - 让我的图像与其余的 edittext 控件高度相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30084664/

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