我必須顯示必須是屏幕大小一半的圖像。Android圖像水平拉長
該活動的主線性佈局有3個線性佈局。
在第一個線性佈局是ImageView哪個高度尺寸必須是屏幕的1/2大小。該圖像從html標籤解析並加載到ImageView和Picasso。
圖片拉長,我想它是正常的。
第二個和第三個佈局必須保持屏幕的1/2大小。提前
感謝:
您可以從圖像中看到它下面。
我必須顯示必須是屏幕大小一半的圖像。Android圖像水平拉長
該活動的主線性佈局有3個線性佈局。
在第一個線性佈局是ImageView哪個高度尺寸必須是屏幕的1/2大小。該圖像從html標籤解析並加載到ImageView和Picasso。
圖片拉長,我想它是正常的。
第二個和第三個佈局必須保持屏幕的1/2大小。提前
感謝:
您可以從圖像中看到它下面。
嘗試使用以下解決方案
在XML文件中更改的ImageView就像那個
<com.nitin.widgets.DynamicImageView
android:id="@+id/newsimageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:paddingTop="5dp"
android:src="@drawable/no_image" />
下面是完整的代碼snippiest沿左側避免薄間隙/右邊緣
DynamicImageView .java
package com.nitin.widgets;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
public class DynamicImageView extends ImageView {
public DynamicImageView(final Context context, final AttributeSet attrs)
{
super(context, attrs);
}
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
final Drawable d = this.getDrawable();
if (d != null) {
//avoid thin vertical gaps along the left/right edges
final int width = MeasureSpec.getSize(widthMeasureSpec);
final int height = (int) Math.ceil(width * (float) d.getIntrinsicHeight()/d.getIntrinsicWidth());
this.setMeasuredDimension(width, height);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
我會建議試試我們這個s olution。它會爲我工作。
請使用scaleType選項CenterCrop,此選項以更好的比例顯示圖像。
<ImageView
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:layout_height="match_parent" />
請嘗試使用此佈局。請根據您的要求設置子佈局佈局的方向。
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout></LinearLayout>
<LinearLayout></LinearLayout>
</LinearLayout>
</LinearLayout>