How can use wrap-content for Relative Layout Without fill Parent - android

Sorry for my bad English,
I set RelativeLayout width wrap_content, but it fill_parent.
here is my code:
<RelativeLayout
android:id="#+id/btnAddToBasket"
android:layout_width="wrap_content"
android:layout_height="#dimen/productDetailsAddToBasketHeight"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:background="#drawable/green_add_to_basket_button"
android:clickable="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgBasketIcon"
android:layout_width="#dimen/productDetailsAddToBasketHeight"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:background="#drawable/green_add_to_basket_icon"
android:padding="5dip"
android:layout_alignParentRight="tr"
android:scaleType="fitCenter"
android:src="#drawable/basket_reverse_icon" />
<ImageView
android:id="#+id/imgHalfCircle"
android:layout_width="10dip"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginBottom="2dip"
android:layout_toLeftOf="#id/imgBasketIcon"
android:scaleType="fitXY"
android:src="#drawable/add_to_basket_half_black" />
<TextView
android:id="#+id/lblAddToBasket"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dip"
android:layout_marginRight="4dip"
android:layout_toLeftOf="#id/imgHalfCircle"
android:gravity="center"
android:text="Add to Basket"
android:textColor="#color/white"
android:textSize="#dimen/SmallTextSize"
android:textStyle="bold" />
</RelativeLayout>
Can I use LinearLayout for this? I want my RelativeLayout children fill right to left. please help!..

Try this
<RelativeLayout android:id="#+id/btnAddToBasket"
android:layout_width="wrap_content"
android:layout_height="#dimen/productDetailsAddToBasketHeight"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:background="#drawable/green_add_to_basket_button"
android:clickable="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgBasketIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:background="#drawable/green_add_to_basket_icon"
android:padding="5dip"
android:layout_alignParentRight="tr"
android:scaleType="fitCenter"
android:src="#drawable/basket_reverse_icon" />
<ImageView
android:id="#+id/imgHalfCircle"
android:layout_width="10dip"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginBottom="2dip"
android:layout_toLeftOf="#id/imgBasketIcon"
android:scaleType="fitXY"
android:src="#drawable/add_to_basket_half_black" />
<TextView
android:id="#+id/lblAddToBasket"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dip"
android:layout_marginRight="4dip"
android:layout_toLeftOf="#id/imgHalfCircle"
android:gravity="center"
android:text="Add to Basket"
android:textColor="#color/white"
android:textSize="#dimen/SmallTextSize"
android:textStyle="bold" />
</RelativeLayout>

Use LinearLayout instead of RelativeLayout as below :-
<LinearLayout
android:id="#+id/btnAddToBasket"
android:layout_width="wrap_content"
android:layout_height="#dimen/productDetailsAddToBasketHeight"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:background="#drawable/green_add_to_basket_button"
android:clickable="true"
android:orientation="horizontal">
<TextView
android:id="#+id/lblAddToBasket"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dip"
android:layout_marginRight="4dip"
android:gravity="center"
android:text="Add to Basket"
android:textColor="#android:color/white"
android:textSize="#dimen/SmallTextSize"
android:textStyle="bold" />
<ImageView
android:id="#+id/imgHalfCircle"
android:layout_width="10dip"
android:layout_height="match_parent"
android:layout_marginBottom="2dip"
android:scaleType="fitXY"
android:src="#drawable/add_to_basket_half_black" />
<ImageView
android:id="#+id/imgBasketIcon"
android:layout_width="#dimen/productDetailsAddToBasketHeight"
android:layout_height="match_parent"
android:background="#drawable/green_add_to_basket_icon"
android:padding="5dip"
android:scaleType="fitCenter"
android:src="#drawable/basket_reverse_icon" />
</LinearLayout>
or if you want to use Relative Layout refer below XML
<RelativeLayout
android:id="#+id/btnAddToBasket"
android:layout_width="wrap_content"
android:layout_height="#dimen/productDetailsAddToBasketHeight"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:background="#drawable/green_add_to_basket_button"
android:clickable="true"
android:orientation="horizontal">
<ImageView
android:id="#+id/imgBasketIcon"
android:layout_width="#dimen/productDetailsAddToBasketHeight"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:background="#drawable/green_add_to_basket_icon"
android:padding="5dip"
android:scaleType="fitCenter"
android:layout_toRightOf="#+id/imgHalfCircle"
android:src="#drawable/basket_reverse_icon" />
<ImageView
android:id="#+id/imgHalfCircle"
android:layout_width="10dip"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginBottom="2dip"
android:layout_toRightOf="#+id/lblAddToBasket"
android:scaleType="fitXY"
android:src="#drawable/add_to_basket_half_black" />
<TextView
android:id="#+id/lblAddToBasket"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dip"
android:layout_marginRight="4dip"
android:gravity="center"
android:text="Add to Basket"
android:textColor="#android:color/white"
android:textSize="#dimen/SmallTextSize"
android:textStyle="bold" />
</RelativeLayout>

please try this. share to improvement.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout android:id="#+id/btnAddToBasket"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="right"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:layoutDirection="rtl"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="#+id/imgBasketIcon"
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="#drawable/email_line"
android:padding="5dip"
android:layout_gravity="right"
android:scaleType="fitCenter"
/>
<ImageView
android:id="#+id/imgHalfCircle"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:layout_gravity="end"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/imgHalfCircl"
android:layout_width="30dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/email_line" />
<ImageView
android:id="#+id/imgHalfCirl"
android:layout_width="30dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/imgHalfCrcl"
android:layout_width="30dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/email_line" />
<ImageView
android:id="#+id/imgHafCirl"
android:layout_width="30dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/imgHafCrl"
android:layout_width="30dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/logo" />
</LinearLayout>
</RelativeLayout>

Related

Can´t add elements to HorizontalScrollView programatically

I'm inserting TextView elements dynamically, but only the last ones are inserted and the first ones are missing.
XML of HorizontalScrollView:
<HorizontalScrollView
android:id="#+id/mainScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:scrollbars="none">
<LinearLayout
android:id="#+id/scrollLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
Full XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backround">
<RelativeLayout
android:id="#+id/article"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout3"
android:layout_marginBottom="15dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="15dp"
android:background="#drawable/edittext">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView35"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
<HorizontalScrollView
android:id="#+id/mainScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:scrollbars="none">
<LinearLayout
android:id="#+id/scrollLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
<ImageView
android:id="#+id/imageView46"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_marginLeft="17dp"
android:layout_toEndOf="#+id/imageView45"
android:layout_toRightOf="#+id/imageView45"
app:srcCompat="#mipmap/likeicon" />
<ImageView
android:id="#+id/imageView45"
android:layout_width="125dp"
android:layout_height="45dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/pujar" />
<ImageView
android:id="#+id/imageView47"
android:layout_width="wrap_content"
android:layout_height="27dp"
android:layout_alignTop="#+id/imageView46"
android:layout_marginRight="13dp"
android:layout_toLeftOf="#+id/imageView45"
android:layout_toStartOf="#+id/imageView45"
app:srcCompat="#mipmap/deleteicon" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout5"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toEndOf="#+id/imageView44"
android:layout_toRightOf="#+id/imageView44"
android:text="Article title"
android:textSize="15sp" />
<ImageView
android:id="#+id/imageView44"
android:layout_width="24dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
app:srcCompat="#mipmap/unknown" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/mainContentImage"
android:layout_width="match_parent"
android:layout_height="255dp"
android:layout_below="#+id/relativeLayout5"
android:background="#mipmap/surf">
</RelativeLayout>
<TextView
android:id="#+id/textView35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/mainContentImage"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Puja actual:"
android:textColor="#color/bidsy"
android:textSize="15sp" />
<TextView
android:id="#+id/textView36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView35"
android:layout_alignBottom="#+id/textView35"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/textView35"
android:layout_toRightOf="#+id/textView35"
android:text="120"
android:textColor="#color/bidsy"
android:textSize="16sp" />
<TextView
android:id="#+id/textView37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView35"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:text="1 Dia 4 horas"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayoutBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/bidsy"
android:visibility="gone">
<ImageView
android:id="#+id/imageView15"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:onClick="searchClick"
android:padding="12dp"
app:srcCompat="#mipmap/search" />
<ImageView
android:id="#+id/imageView144"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:clickable="true"
android:onClick="menuClick"
android:padding="10dp"
app:srcCompat="#mipmap/menu" />
<ImageView
android:id="#+id/imageViewBar"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#mipmap/title" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayoutSearchBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayoutBar"
android:background="#color/bidsy">
<EditText
android:id="#+id/editText13"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="125dp"
android:background="#drawable/edittextsearch"
android:ems="10"
android:gravity="center"
android:hint="Busca en Bidsy!"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#E95355" />
<ImageView
android:id="#+id/imageView155"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="12dp"
app:srcCompat="#mipmap/search" />
<ImageView
android:id="#+id/imageView14"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:clickable="true"
android:onClick="menuClick"
android:padding="10dp"
app:srcCompat="#mipmap/menu" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayoutSearchBar"
android:background="#color/white"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/tab1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="tabClick">
<RelativeLayout
android:id="#+id/bar1"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/bidsy">
</RelativeLayout>
<ImageView
android:id="#+id/imageView4354"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/bidsytab" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tab2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="tabClick">
<RelativeLayout
android:id="#+id/bar2"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/bidsy">
</RelativeLayout>
<ImageView
android:id="#+id/imageView4351"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/bidsytab" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tab3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="tabClick">
<RelativeLayout
android:id="#+id/bar3"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/bidsy">
</RelativeLayout>
<ImageView
android:id="#+id/imageView4356"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/bidsytab" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tab4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="tabClick">
<RelativeLayout
android:id="#+id/bar4"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/bidsy">
</RelativeLayout>
<ImageView
android:id="#+id/imageView43523"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/bidsytab" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tab5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="tabClick">
<RelativeLayout
android:id="#+id/bar5"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/bidsy">
</RelativeLayout>
<ImageView
android:id="#+id/imageView435233"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/bidsytab" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tab6"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="tabClick">
<RelativeLayout
android:id="#+id/bar6"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/bidsy">
</RelativeLayout>
<ImageView
android:id="#+id/imageView435"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/bidsytab" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tab7"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="tabClick">
<RelativeLayout
android:id="#+id/bar7"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/bidsy">
</RelativeLayout>
<ImageView
android:id="#+id/imageView43"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:srcCompat="#mipmap/bidsytab" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Code to load elements:
private void loadScrollElements() {
LinearLayout yourLayout = (LinearLayout) findViewById(R.id.scrollLayout);
for (int i = 1; i < 25; i++) {
TextView tv = new TextView(this);
tv.setText(i + "");
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
tv.setTextSize(20);
yourLayout.addView(tv);
}
}
I see in mainScroll items from 11 to 24 + empty space.
Curiously that blank space seems to be the space that would take the missing elements at the beginning.
Why I don´t see 1..10 items?
The android:layout_gravity="center" of the LinearLayout causes the problem. When you change it to android:layout_gravity="center_vertical", all the TextView's will be visible again.
I'm not sure, but I guess that because the TextView's are added programmatically the LinearLayout miscalculates it's horizontal center.
Please correct me if I'm wrong.

HorizontalScrollView not working

I am unable to scroll horizontally using HorizontalScrollView, but the same code in other files appears to work fine. I am unable to find an error in this file.
Here is the HorizontalScrollView xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
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:background="#87E886"
android:orientation="horizontal">
<HorizontalScrollView
android:id="#+id/scrollView1"
android:layout_width="2200dp"
android:layout_height="550dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--D2-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageView16"
android:src="#drawable/des1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageView17"
android:src="#drawable/img_bahay"
android:layout_below="#+id/imageView16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageView18"
android:src="#drawable/des_bahay"
android:layout_below="#+id/imageView17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageView19"
android:layout_below="#+id/imageView18"
android:src="#drawable/desc_bahay"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_marginTop="180dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="30dp"
android:layout_width="205dp"
android:layout_height="100dp"
android:id="#+id/xaxaw"
android:src="#drawable/arrow"
></ImageView>
<!--D3-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewa16"
android:src="#drawable/des2"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageViewa17"
android:src="#drawable/img_chinatown"
android:layout_below="#+id/imageViewa16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewa18"
android:src="#drawable/des_chinatown"
android:layout_below="#+id/imageViewa17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageViewa19"
android:src="#drawable/desc_chinatown"
android:layout_below="#+id/imageViewa18"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
<!-- <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Estimated Duration:"
android:id="#+id/textView13"
android:textColor="#000000"
android:layout_below="#+id/imageView19"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView14"
android:textColor="#000000"
android:layout_below="#+id/textView13"
android:layout_alignParentStart="true"
android:layout_marginLeft="35dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Estimated Distance:"
android:id="#+id/textView15"
android:textColor="#000000"
android:layout_alignTop="#+id/textView13"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView16"
android:textColor="#000000"
android:layout_marginLeft="35dp"
android:layout_below="#+id/textView15"
android:layout_alignStart="#+id/textView15"/> -->
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_marginTop="180dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="30dp"
android:layout_width="205dp"
android:layout_height="100dp"
android:id="#+id/arrow1"
android:src="#drawable/arrow"
></ImageView>
<!-- D4-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaa16"
android:src="#drawable/des3"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageViewaa17"
android:src="#drawable/img_goodwill"
android:layout_below="#+id/imageViewaa16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaa18"
android:src="#drawable/des_goodwill"
android:layout_below="#+id/imageViewaa17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageViewaa19"
android:src="#drawable/desc_goodwill"
android:layout_below="#+id/imageViewaa18"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_marginTop="180dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="30dp"
android:layout_width="205dp"
android:layout_height="100dp"
android:id="#+id/arrow53"
android:src="#drawable/arrow"
></ImageView>
<!--D5-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaag16"
android:src="#drawable/des4"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageViewaag17"
android:src="#drawable/img_chcemetery"
android:layout_below="#+id/imageViewaag16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaag18"
android:src="#drawable/des_chcemetery"
android:layout_below="#+id/imageViewaag17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageViewaag19"
android:src="#drawable/desc_chcemetery"
android:layout_below="#+id/imageViewaag18"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Make HorizontalScrollView's with to "wrap_content" and maintain a single child to the HorizontalScrollView i.e.
<HorizontalScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
rest of the code here......
</LinearLayout>
</HorizontalScrollView>
it seems like you have forgotten to end the LinearLayout tag before ending HorizontalScrollView . Your code should look like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
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:background="#87E886"
android:orientation="horizontal">
<HorizontalScrollView
android:id="#+id/scrollView1"
android:layout_width="2200dp"
android:layout_height="550dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--D2-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageView16"
android:src="#drawable/des1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageView17"
android:src="#drawable/img_bahay"
android:layout_below="#+id/imageView16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageView18"
android:src="#drawable/des_bahay"
android:layout_below="#+id/imageView17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageView19"
android:layout_below="#+id/imageView18"
android:src="#drawable/desc_bahay"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_marginTop="180dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="30dp"
android:layout_width="205dp"
android:layout_height="100dp"
android:id="#+id/xaxaw"
android:src="#drawable/arrow"
></ImageView>
<!--D3-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewa16"
android:src="#drawable/des2"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageViewa17"
android:src="#drawable/img_chinatown"
android:layout_below="#+id/imageViewa16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewa18"
android:src="#drawable/des_chinatown"
android:layout_below="#+id/imageViewa17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageViewa19"
android:src="#drawable/desc_chinatown"
android:layout_below="#+id/imageViewa18"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
<!-- <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Estimated Duration:"
android:id="#+id/textView13"
android:textColor="#000000"
android:layout_below="#+id/imageView19"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView14"
android:textColor="#000000"
android:layout_below="#+id/textView13"
android:layout_alignParentStart="true"
android:layout_marginLeft="35dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Estimated Distance:"
android:id="#+id/textView15"
android:textColor="#000000"
android:layout_alignTop="#+id/textView13"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView16"
android:textColor="#000000"
android:layout_marginLeft="35dp"
android:layout_below="#+id/textView15"
android:layout_alignStart="#+id/textView15"/> -->
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_marginTop="180dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="30dp"
android:layout_width="205dp"
android:layout_height="100dp"
android:id="#+id/arrow1"
android:src="#drawable/arrow"
></ImageView>
<!-- D4-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaa16"
android:src="#drawable/des3"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageViewaa17"
android:src="#drawable/img_goodwill"
android:layout_below="#+id/imageViewaa16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaa18"
android:src="#drawable/des_goodwill"
android:layout_below="#+id/imageViewaa17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageViewaa19"
android:src="#drawable/desc_goodwill"
android:layout_below="#+id/imageViewaa18"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_marginTop="180dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="30dp"
android:layout_width="205dp"
android:layout_height="100dp"
android:id="#+id/arrow53"
android:src="#drawable/arrow"
></ImageView>
<!--D5-->
<LinearLayout
android:layout_width="310dp"
android:layout_height="520dp"
android:background="#024500"
android:layout_marginLeft="10dp">
<RelativeLayout
android:layout_width="290dp"
android:layout_height="499dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="#BEFFB6"
android:layout_marginLeft="10dp"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaag16"
android:src="#drawable/des4"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="220dp"
android:layout_height="190dp"
android:id="#+id/imageViewaag17"
android:src="#drawable/img_chcemetery"
android:layout_below="#+id/imageViewaag16"
android:layout_alignParentStart="true"
android:layout_marginLeft="35sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/imageViewaag18"
android:src="#drawable/des_chcemetery"
android:layout_below="#+id/imageViewaag17"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/imageViewaag19"
android:src="#drawable/desc_chcemetery"
android:layout_below="#+id/imageViewaag18"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
ScrollView or in your case HorizontalScrollView can only have one direct child view. Like :
<ScrollView>
<LinearLayout>
// add all the required views here.
</Linearlayout>
</Scrollview>
Although, you can add mulitiple views inside that Linear or any other layout.

How to fully fill the image button with images?

I have these image buttons, the image for the image button are store in the
drawable file. However, i just cannot fill the image button with the image.
There will still be some empty space left which make it not that beautiful.
Is there any way to make the image button fully fill with image? Here shows
my image button xml code.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/RelativeLayout01"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="#drawable/homepage"
android:layout_marginLeft="80dp"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/buttonSignUP"
android:layout_gravity="right"
android:layout_marginLeft="40dp"/>
</LinearLayout>
<SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchView"
android:layout_below="#+id/viewFlipper"
android:layout_alignParentStart="true"
android:text="Search a product"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Featured promotion"
android:id="#+id/textView"
android:layout_below="#+id/searchView"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<ViewFlipper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view_flipper"
android:layout_alignEnd="#+id/imageButton2"
android:layout_marginTop="20dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="#drawable/banner5" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="#drawable/banner6" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="#drawable/banner7" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="#drawable/banner8" />
</RelativeLayout>
</ViewFlipper>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Categories"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_marginTop="40dp" />
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton"
android:layout_below="#+id/textView2"
android:src="#drawable/fashion"
android:layout_toStartOf="#+id/imageButton3" />
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton2"
android:layout_alignParentEnd="true"
android:layout_below="#+id/textView2"
android:src="#drawable/book"
android:layout_above="#+id/imageButton5"
android:layout_gravity="center_vertical"
android:layout_marginLeft="40dp"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton3"
android:src="#drawable/sport"
android:layout_alignTop="#+id/imageButton2"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#+id/imageButton2"
android:layout_gravity="center_vertical" />
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton4"
android:layout_below="#+id/imageButton"
android:layout_alignParentStart="true"
android:src="#drawable/healthcare"
android:layout_marginLeft="40dp"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton5"
android:layout_alignTop="#+id/imageButton4"
android:layout_alignEnd="#+id/imageButton2"
android:src="#drawable/computer"
android:layout_alignBottom="#+id/imageButton4"
android:layout_alignStart="#+id/imageButton2" />
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton6"
android:layout_alignBottom="#+id/imageButton4"
android:src="#drawable/phone"
android:layout_alignTop="#+id/imageButton4"
android:layout_alignEnd="#+id/imageButton3"
android:layout_toEndOf="#+id/imageButton4"
android:layout_marginLeft="40dp"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton7"
android:src="#drawable/stationary"
android:layout_below="#+id/imageButton4"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton8"
android:src="#drawable/others"
android:layout_below="#+id/imageButton5"
android:layout_alignStart="#+id/imageButton6"
android:layout_alignEnd="#+id/imageButton6"
android:layout_marginLeft="40dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Yes you can use android:scaleType="fitXY"
OR
android:scaleType="fitCenter"
For eg.
<ImageButton
android:id="#+id/imageButton"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_below="#+id/textView2"
android:adjustViewBounds="true"
android:background="#null"
android:src="#drawable/fashion"
android:scaleType="fitCenter" />
Well you can use the android:scaleType attribute to fill the ImageButton. I generally use fitXY or fitCenter to cover the ImageButton with the image. To remove gray background, use android:background="#null". For example -
<ImageButton
android:layout_width="120dp"
android:layout_height="100dp"
android:id="#+id/imageButton2"
android:layout_alignParentEnd="true"
android:layout_below="#+id/textView2"
android:src="#drawable/book"
android:layout_above="#+id/imageButton5"
android:layout_gravity="center_vertical"
android:layout_marginLeft="40dp"
android:scaleType="fitXY"
android:background="#null" />
Add ScaleType
android:scaleType="fitXY"
and Background as null to remove grey background
android:background="#null"
you can use android:scaleType="fitXY"

How to align Buttons under a ListView?

I'm trying to align a number of buttons under a list of items.
It's appearing as follows:
But I need it to appear as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="7dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myImage" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[TextView text]"
android:textSize="20sp"
android:layout_gravity="center" />
</LinearLayout>
<TextView
android:id="#+id/lblOverviewText"
android:textStyle="bold"
android:textSize="15sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1" />
<TextView
android:id="#+id/lblEngineer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblOverviewText" />
<TextView
android:id="#+id/lblAlarmEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblEngineer" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/lblAlarmEvents" />
<LinearLayout
android:id="#+id/linearLayoutSetUnsetButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/list">
<ImageButton
android:id="#+id/btnFullSet"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Full Set"
android:layout_margin="5dp"
android:src="#drawable/lock_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnPartsetA"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Part A"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/PartSetA_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnPartsetB"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Part B"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/PartSetB_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnUnset"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Unset"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/Unset_128"
android:scaleType="fitCenter"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
Try this way
Make your listview wrap_content
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lblAlarmEvents" />
<LinearLayout
android:id="#+id/linearLayoutSetUnsetButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_below="#+id/list">
XML file will be like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="7dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myImage" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[TextView text]"
android:textSize="20sp"
android:layout_gravity="center" />
</LinearLayout>
<TextView
android:id="#+id/lblOverviewText"
android:textStyle="bold"
android:textSize="15sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1" />
<TextView
android:id="#+id/lblEngineer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblOverviewText" />
<TextView
android:id="#+id/lblAlarmEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblEngineer" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/lblAlarmEvents" />
<LinearLayout
android:id="#+id/linearLayoutSetUnsetButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/list">
<ImageButton
android:id="#+id/btnFullSet"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Full Set"
android:layout_margin="5dp"
android:src="#drawable/lock_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnPartsetA"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Part A"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/PartSetA_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnPartsetB"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Part B"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/PartSetB_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnUnset"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Unset"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/Unset_128"
android:scaleType="fitCenter"
android:visibility="gone" />
</LinearLayout>
Or If you want your image button's parent layout as a footer set the xml like this:
XML file will be like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="7dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myImage" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[TextView text]"
android:textSize="20sp"
android:layout_gravity="center" />
</LinearLayout>
<TextView
android:id="#+id/lblOverviewText"
android:textStyle="bold"
android:textSize="15sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1" />
<TextView
android:id="#+id/lblEngineer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblOverviewText" />
<TextView
android:id="#+id/lblAlarmEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblEngineer" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/lblAlarmEvents" />
<LinearLayout
android:id="#+id/linearLayoutSetUnsetButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/btnFullSet"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Full Set"
android:layout_margin="5dp"
android:src="#drawable/lock_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnPartsetA"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Part A"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/PartSetA_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnPartsetB"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Part B"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/PartSetB_128"
android:scaleType="fitCenter" />
<ImageButton
android:id="#+id/btnUnset"
android:background="#null"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Unset"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:src="#drawable/Unset_128"
android:scaleType="fitCenter"
android:visibility="gone" />
</LinearLayout>

Listview item fits to row

I have a listview with two textviews in a row like name and result. I want to fit the textview to the row because I need to set a background color to the second textview.I have tried "match_parent"fill_parent"..etc
//items.xml
<ImageView
android:id="#+id/imgViewLogo"
android:layout_width="22dip"
android:layout_height="22dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="center"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/txtViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtViewDescription"
android:layout_alignBottom="#+id/txtViewDescription"
android:layout_marginLeft="6dp"
android:layout_toRightOf="#+id/imgViewLogo"
android:text="TextView"
android:textStyle="bold" />
<MyTextView
android:id="#+id/txtViewDescription"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imgViewLogo"
android:layout_marginRight="33dp"
android:layout_gravity="center"
android:text="TextView"
android:textStyle="bold" />
<ImageView
android:id="#+id/temperrr"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/resultarrawnocolor" />
</RelativeLayout>
// listview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/gl1"
style="?android:attr/buttonStyleSmall"
android:layout_width="64dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/back"
android:gravity="center_vertical"
android:onClick="backMan" />
<TextView
android:id="#+id/textVie3"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/gl1"
android:background="#drawable/header_line" />
<Button
android:id="#+id/gl2"
style="?android:attr/buttonStyleSmall"
android:layout_width="64dp"
android:layout_height="40dp"
android:layout_above="#+id/textVie3"
android:layout_alignParentRight="true"
android:background="#drawable/info"
android:gravity="center_vertical"
android:onClick="info" />
<TextView
android:id="#+id/textVie1"
android:layout_width="135dp"
android:layout_height="30dp"
android:layout_alignBaseline="#+id/gl2"
android:layout_alignBottom="#+id/gl2"
android:layout_centerHorizontal="true"
android:background="#drawable/uchek_header"
android:gravity="center" />
<TextView
android:id="#+id/bgnf1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textVie3"
android:background="#drawable/main_bag" />
<TextView
android:id="#+id/myTextView1"
android:layout_width="375dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/bgnf1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/textviewtableheader"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Result"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="#+id/btnemail"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/email"/>
<Button
android:id="#+id/btnsave"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/save"
/>
<Button
android:id="#+id/btnrec"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/myTextView1"
android:background="#drawable/rec"
/>
<ListView
android:id="#+id/lv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/btnemail"
android:layout_alignLeft="#+id/myTextView1"
android:layout_alignRight="#+id/myTextView1"
android:layout_below="#+id/myTextView1"
android:background="#color/White"
android:divider="#drawable/tabledivider"
android:dividerHeight="1dp"
android:listSelector="#drawable/listcolor"
tools:listitem="#android:layout/simple_list_item_1" >
</ListView>
</RelativeLayout>
If you want the height to be of icon size you can use this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:weightSum="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:background="#F00"
android:gravity="center_vertical"
android:text="Envelope" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:background="#990"
android:gravity="center_vertical"
android:text="1000ml/Dl" />
</LinearLayout>
</LinearLayout>
Try distributing the weight of ImageView , TextView , TextView and ImageView to get the desired result.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imgViewLogo"
android:layout_width="22dip"
android:layout_height="22dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="center"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/temperrr"
android:layout_toRightOf="#+id/imgViewLogo"
android:orientation="horizontal"
android:weightSum="1.0" >
<TextView
android:id="#+id/txtViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtViewDescription"
android:layout_alignBottom="#+id/txtViewDescription"
android:layout_toRightOf="#+id/imgViewLogo"
android:layout_weight="0.5"
android:background="#ff0000"
android:text="TextView"
android:textStyle="bold" />
<TextView
android:id="#+id/txtViewDescription"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imgViewLogo"
android:layout_gravity="center"
android:layout_weight="0.5"
android:background="#ffff00"
android:text="TextView"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/temperrr"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
may be this will help, i edited the answer,check now

Categories

Resources