Reputation: 498
I'm trying to make View,blue bar, show out in a list but it seems can't. Note : the image are setup later while creating list view
<?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="wrap_content"
android:background="@color/white">
<LinearLayout
android:id="@+id/list_img_ll"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgList1"
android:layout_width="wrap_content"
android:layout_height="80dp"
/>
</LinearLayout>
<View android:id="@+id/state_open"
android:layout_alignParentRight="true"
android:layout_width="20dp"
android:layout_height="match_parent"
android:background="@color/CVBlue" />
</RelativeLayout>
getView() Method
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RecordHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.imageItem = (ImageView) row.findViewById(R.id.imgList1);
holder.stateView = row.findViewById(R.id.state_open);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
Item item = data.get(position);
holder.imageItem.setImageBitmap(item.getImage());
return row;
}
This is the result. Notice the top right corner it seems to try generate but not work. Also when I set the height of the relativelayout it works and I'm very confuse. Image of the not working one https://i.sstatic.net/xAlpg.png
This is something I want without having to config the relativelayout size https://i.sstatic.net/SCRTu.png
Upvotes: 1
Views: 1791
Reputation: 6821
The problem is your LinearLayout. Add the following attribute:
android:layout_toLeftOf="@+id/state_open"
The issue is that you set LinearLayout's width to match_parent, which takes up the entire screen's width. Doesn't leave any space left for the View. By having it set to the left of, it'll prevent it taking all the available space for the View.
Got it. Very strange. On the state_open view add:
android:layout_alignTop="@+id/list_img_ll"
android:layout_alignBottom="@+id/list_img_ll"
The problem is that the state_open view doesn't know how much height to give the color value...even though the view is getting the appropriate height. Aligning it to the LinearLayout works. Alternative solution is to just give the View an actual dp size instead of match_parent. Ie, 80dp. Oddest thing ever.
Upvotes: 2
Reputation: 737
Try this:
<?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="wrap_content"
android:background="@color/white">
<View android:id="@+id/state_open"
android:layout_alignParentRight="true"
android:layout_width="20dp"
android:layout_height="match_parent"
android:background="@color/CVBlue" />
<LinearLayout
android:id="@+id/list_img_ll"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_toLeftOf="@id/state_open">
<ImageView
android:id="@+id/imgList1"
android:layout_width="wrap_content"
android:layout_height="80dp"/>
</LinearLayout>
</RelativeLayout>
Upvotes: -1