Android 安卓两个完全适合屏幕的图像视图
我正在处理一个ListView,每行有两个正方形的ImageView。可绘制内容由url动态提供。问题是图片与屏幕不匹配 来自url的图像已经是方形的,但我希望图像可以放大或缩小以适应屏幕 现在它看起来像第一个截图,但我希望它们看起来像第二个Android 安卓两个完全适合屏幕的图像视图,android,listview,imageview,Android,Listview,Imageview,我正在处理一个ListView,每行有两个正方形的ImageView。可绘制内容由url动态提供。问题是图片与屏幕不匹配 来自url的图像已经是方形的,但我希望图像可以放大或缩小以适应屏幕 现在它看起来像第一个截图,但我希望它们看起来像第二个 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.c
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
>
<ImageView
android:id="@+id/list_item_image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<ImageView
android:id="@+id/list_item_image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
</LinearLayout>
这是适配器
public class ListAdapter extends ArrayAdapter<ListItem>{
private ArrayList<ListItem> items;
private Activity context;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
public ListAdapter(Activity context, int textViewResourceId, ArrayList<ListItem> items)
{
super(context, textViewResourceId, items);
this.items = items;
this.context = context;
inflater = (LayoutInflater)context.getLayoutInflater();
imageLoader = new ImageLoader(context);
}
public static class ViewHolder{
public ImageView image1;
public ImageView image2;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
View rowView = convertView;
ViewHolder holder;
if (rowView == null) {
rowView = inflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.image1 = (ImageView)rowView.findViewById(R.id.list_item_image1);
holder.image2 = (ImageView)rowView.findViewById(R.id.list_item_image2);
rowView.setTag(holder);
}
else
holder = (ViewHolder)rowView.getTag();
imageLoader.DisplayImage("http://dev.ts.hs.kr/jjhoon713/images/1400023976194990.jpg", holder.image1);
imageLoader.DisplayImage("http://dev.ts.hs.kr/jjhoon713/images/1400023976194990.jpg", holder.image2);
return rowView;
}
公共类ListAdapter扩展了ArrayAdapter{
私有ArrayList项;
私人活动语境;
专用静态充气机=空;
公共图像加载器;
公共ListAdapter(活动上下文、int-textViewResourceId、ArrayList项)
{
super(上下文、textViewResourceId、项);
这个项目=项目;
this.context=上下文;
充气器=(LayoutInflater)上下文。getLayoutInflater();
imageLoader=新的imageLoader(上下文);
}
公共静态类视图持有者{
公共图像查看图像1;
公共图像查看图像2;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组视图组){
视图行视图=转换视图;
视窗座;
if(rowView==null){
rowView=充气机。充气(R.layout.list_项,空);
holder=新的ViewHolder();
holder.image1=(ImageView)rowView.findViewById(R.id.list\u item\u image1);
holder.image2=(ImageView)rowView.findViewById(R.id.list\u item\u image2);
rowView.setTag(支架);
}
其他的
holder=(ViewHolder)rowView.getTag();
imageLoader.DisplayImage(“http://dev.ts.hs.kr/jjhoon713/images/1400023976194990.jpg“,持有人。图像1);
imageLoader.DisplayImage(“http://dev.ts.hs.kr/jjhoon713/images/1400023976194990.jpg“,持有人。图像2);
返回行视图;
}
}尝试以下代码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2"
>
<ImageView
android:id="@+id/list_item_image1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:scaleType="centerCrop"
/>
<ImageView
android:id="@+id/list_item_image2"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"
android:scaleType="centerCrop"
/>
</LinearLayout>
尝试以下代码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2"
>
<ImageView
android:id="@+id/list_item_image1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:scaleType="centerCrop"
/>
<ImageView
android:id="@+id/list_item_image2"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"
android:scaleType="centerCrop"
/>
</LinearLayout>
像这样试试
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/list_item_image1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:scaleType="fitXY"
/>
<ImageView
android:id="@+id/list_item_image2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:scaleType="fitXY"
/>
</LinearLayout>
像这样试试
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/list_item_image1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:scaleType="fitXY"
/>
<ImageView
android:id="@+id/list_item_image2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:scaleType="fitXY"
/>
</LinearLayout>
采用权重总和为2的线性布局,并为每个图像视图分配1个权重,如下所示:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" // you can hardcode height if your view
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="@+id/imageview1"
android:layout_width="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:layout_height="wrap_content" // can change to fill parent if you hardcode the height of your view
android:src= ""// your image if static, else set dynamically
android:scaleType="fitxy"/>
<ImageView
android:id="@+id/imageview2"
android:layout_height=""// can change to fill parent if you hardcode the height of your view
android:layout_width="0dp"
android:adjustViewBounds="true"
android:layout_weight="1"
android:src="wrap_content" // your image if static, else set dynamically
android:scaleType="fitxy"/>
</LinearLayout>
采用权重总和为2的线性布局,并为每个图像视图分配1个权重,如下所示:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" // you can hardcode height if your view
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="@+id/imageview1"
android:layout_width="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:layout_height="wrap_content" // can change to fill parent if you hardcode the height of your view
android:src= ""// your image if static, else set dynamically
android:scaleType="fitxy"/>
<ImageView
android:id="@+id/imageview2"
android:layout_height=""// can change to fill parent if you hardcode the height of your view
android:layout_width="0dp"
android:adjustViewBounds="true"
android:layout_weight="1"
android:src="wrap_content" // your image if static, else set dynamically
android:scaleType="fitxy"/>
</LinearLayout>
我的问题是list\u view.xml的布局宽度是包装内容 因为列表项的父项是列表视图,所以权重不起作用
我将它们改为填充父对象,现在它运行良好我的问题是list\u view.xml的布局宽度是包装内容 因为列表项的父项是列表视图,所以权重不起作用
我将它们改为填充,现在效果很好你可能想用a代替。你可能想用a代替。我试过给它们配重,但没用。无论如何谢谢你!我试过给他们举重,但没用。无论如何谢谢你!权重不起作用,因为图像是动态给定的。谢谢thoughweight不起作用,因为图像是动态给出的。谢谢