相对布局内的Imageview不会拉伸全视图

时间:2014-05-12 15:13:26

标签: android android-layout listview

如果我给这个项目充气并在我的列表视图中显示它,那么imageview不会填充父项,即它只是伸展到宽度,但它不会扩展到视图高度。

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="5dp">

     <ImageView
         android:layout_width="10dp"
         android:layout_height="match_parent"
         android:layout_alignParentTop="true"
         android:layout_alignParentLeft="true"
         android:layout_marginTop="2dp"
         android:layout_marginLeft="5dp"
         android:layout_marginRight="5dp"
         android:layout_marginBottom="5dp"
         android:id="@+id/ID_task_item_priority"
         android:src="@color/abs__background_holo_dark"/>

    <TextView 
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Your title"
         android:id="@+id/ID_task_item_title"
         android:singleLine="true"
         android:ellipsize="end"
         android:layout_toRightOf="@+id/ID_task_item_priority"
         android:layout_marginRight="40dp"
         android:textSize="25sp"
        />

    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ID_task_item_notes"
        android:layout_below="@+id/ID_task_item_title"
        android:maxLines="3"
        android:ellipsize="end"
        android:text="Your note"
        android:layout_toRightOf="@+id/ID_task_item_priority"
        android:layout_marginRight="4dp"
        android:textSize="15sp"
        />

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/id_due_date"
        android:layout_below="@+id/ID_task_item_notes"
        android:layout_alignParentRight="true"
        android:layout_marginTop="5dp"
        android:text="10-2-2014"
        android:textSize="15sp"
        />

         <CheckBox
            android:id="@+id/ID_task_item_is_completed_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/ID_task_item_title"
            android:layout_alignBottom="@+id/ID_task_item_title"
            android:layout_alignParentRight="true"
            android:focusable="false"
            android:layout_marginRight="4dp" /> 

</RelativeLayout>

项目图片enter image description here

1 个答案:

答案 0 :(得分:2)

根据设备配置设置图像布局参数运行时间

使用此代码设置与屏幕参数

相同的图像视图宽度和高度
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.rl_main);
    RelativeLayout.LayoutParams lparams= new RelativeLayout.LayoutParams(width,height);

    ImageView iv= (ImageView)findViewById(R.id.imageView1);
    relativeLayout.removeView(iv);
    relativeLayout.addView(iv,lparams);

这可能对您有所帮助