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"
Related
I'm trying to create two number pickers in android. However i try to center them both at the bottom. I tried to mix up relative and linear layout, but i was not able to fix it.
The images shows how the buttons are placed at the moment. The red squares show how i want the buttons to be displayed.
Hope you can help me.
<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"
tools:context="com.pvdl.ndwatch.NDwatchActivity$PlaceholderFragment" >
<ImageView
android:id="#+id/background"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:scaleType="centerCrop"
android:src="#drawable/background" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/nd_text"
android:textColor="#color/red"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:src="#drawable/ic_launcher" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="90dp"
android:background="#00ABCC" />
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="20dp"
android:text="#string/title"
android:textColor="#404041"
android:textSize="60sp" />
<TextView
android:id="#+id/title2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="30dp"
android:text="#string/title2"
android:textColor="#404041"
android:textSize="50sp" />
<RelativeLayout
android:id="#+id/frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true" >
</RelativeLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="270dp"
android:layout_height="270dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:indeterminate="false"
android:max="100"
android:progress="0"
android:progressDrawable="#drawable/circular_progress_bar" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBottom="#+id/background"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:background="#android:color/transparent"
android:onClick="onNDstart"
android:scaleType="fitXY"
android:src="#drawable/custom_button" />
<Chronometer
android:id="#+id/chronometer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:background="#android:color/transparent"
android:text="Chronometer"
android:textColor="#000000"
android:textSize="70sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/background"
android:layout_marginBottom="40dp"
android:layout_centerHorizontal="true"
android:text="#string/start"
android:textColor="#color/red"
android:textStyle="bold" />
<NumberPicker
android:id="#+id/numberPicker2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:entries="#array/shutter_times"
/>
<NumberPicker
android:id="#+id/numberPicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:entries="#array/nd_values"
android:gravity="bottom" />
</RelativeLayout>
Change your xml to this:
<RelativeLayout ...>
....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="2" >
<NumberPicker
android:id="#+id/numberPicker2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/shutter_times" />
<NumberPicker
android:id="#+id/numberPicker1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/nd_values" />
</LinearLayout>
</RelativeLayout>
If you want a space between the buttons just add a paddingRight to the left button and the same value to the paddingLeft of the right button.
Hope this helps.
In my action bar, I want the icon and title text to be centered horizontally. Here's what I'm getting:
The action bar is using a RelativeLayout. The icon image and title text are in a LinearLayout which has android:layout_centerHorizontal="true", but the linear layout is not centering. Here's the layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#dddddd" >
<ImageButton
android:id="#+id/leftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="#null"
android:contentDescription=""
android:scaleType="centerInside"
android:src="#drawable/ic_drawer" />
<LinearLayout
android:id="#+id/titleParentLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/titleImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:scaleType="centerInside"
android:src="#drawable/icon_orig" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:singleLine="true"
android:text="#string/app_name"
android:textColor="#484848"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/rightSideParentLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#dddddd"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/rightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="#null"
android:contentDescription=""
android:scaleType="centerInside"
android:src="#drawable/addbutton" />
</LinearLayout>
</RelativeLayout>
EDIT: Both answers give me this:
As you can see, the icon and title are still not centered.
You can try using LinearLayout as follows...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#dddddd"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/leftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="#null"
android:contentDescription=""
android:scaleType="centerInside"
android:src="#drawable/ic_drawer" />
<LinearLayout
android:id="#+id/titleParentLayout"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center" >
<ImageView
android:id="#+id/titleImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:scaleType="centerInside"
android:src="#drawable/ic_orig" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:singleLine="true"
android:text="#string/app_name"
android:textColor="#484848"
android:textSize="18dp" />
</LinearLayout>
<ImageButton
android:id="#+id/rightButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="#null"
android:contentDescription=""
android:scaleType="centerInside"
android:src="#drawable/addbutton" />
</LinearLayout>
in java code use this for android-version 3.0 to upper
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setCustomView(R.layout.custom_actionbar);
xml file custom_actionbar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#dddddd">
<ImageButton
android:id="#+id/leftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dip"
android:background="#null"
android:contentDescription=""
android:scaleType="centerInside"
android:src="#drawable/ic_drawer" />
<LinearLayout
android:id="#+id/titleParentLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageView
android:id="#+id/titleImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:scaleType="centerInside"
android:src="#drawable/icon_orig" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:singleLine="true"
android:text="#string/app_name"
android:textColor="#484848"
android:textSize="18sp" />
</LinearLayout>
<ImageButton
android:id="#+id/rightButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="10dip"
android:gravity="center_vertical"
android:background="#null"
android:contentDescription=""
android:scaleType="centerInside"
android:src="#drawable/addbutton" />
</LinearLayout>
EDIT : Screenshot from Samsung tab2
In the below linear layout, how can I get the image for the first ImageView to be aligned to the left...
<LinearLayout
android:id="#+id/id1"
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#ABABAB"
android:weightSum="3"
android:gravity="center_vertical"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="2"
android:clickable="false"
android:contentDescription="Button"
android:src="#drawable/ic_launcher1" />
<ImageView
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:contentDescription="Button"
android:src="#drawable/ic_action_refresh"
/>
<ImageView
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:contentDescription="Button"
android:src="#drawable/ic_action_settings"
/>
</LinearLayout>
Have tried to do it various ways, but no success so far. Any help is appreciated.
My guess is that the scaleType is causing your images to be centered, even though the views may line up. To fix this, Just set the scaleType attribute for both:
android:scaleType="fitStart"
How about this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/imageView1"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
try this code instead of :take relative layout for it
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/id1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ABABAB"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="3" >
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:contentDescription="Button"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/button3"
android:contentDescription="Button"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="Button"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
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
I want each TextView appear under each ImageButton but the TextView in my case does not appear at all and I don't understand why. Thank you for helping.
This is my activity.xml :
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="#drawable/logo" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageButtonProjet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/projet" />
<ImageButton
android:id="#+id/imageButtonWorkitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/workitem" />
<ImageButton
android:id="#+id/imageButtonUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/user" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageButtonProjet"
android:layout_marginLeft="32dp"
android:text="Projects"
android:textColor="#color/text_color" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageButtonWorkitem"
android:layout_marginLeft="62dp"
android:text="WorkItem"
android:textColor="#color/text_color" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageButtonUser"
android:layout_marginBottom="28dp"
android:layout_marginLeft="65dp"
android:text="Users"
android:textColor="#color/text_color" >
</TextView>
</LinearLayout>
I would greatly appreciate your help.Thanks in advance
layout_below works only for relative layouts.If you still want to do using LinearLayout then here is how.You are just using one LinearLayout that has a horizontal orientation. All this does it arrange the items horizontally and so the textviews go out of the screen. You need a 2 child LinearLayouts that has orientation set to horizontal and the parent with orientation vertical.
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="#drawable/logo" />
<LinearLayout
android:id="#+id/linearLayout_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageButtonProjet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/projet" />
<ImageButton
android:id="#+id/imageButtonWorkitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/workitem" />
<ImageButton
android:id="#+id/imageButtonUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/user" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:text="Projects"
android:textColor="#color/text_color" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="62dp"
android:text="WorkItem"
android:textColor="#color/text_color" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="28dp"
android:layout_marginLeft="65dp"
android:text="Users"
android:textColor="#color/text_color" >
</TextView>
</LinearLayout>
</LinearLayout>
android:layout_below
Doesn't apply to LinearLayout. You should be using RelativeLayout to force items to appear in positions in relation to each other.
Depending on where you want your ImageButtons to appear, you might need to add something like
<ImageButton
android:id="#+id/imageButtonWorkitem"
android:layout_below="#id/imageButtonWorkitem"
or
<ImageButton
android:id="#+id/imageButtonWorkitem"
android:layout_toRightOf="#id/imageButtonWorkitem"
You need to alternate between your imageviews within the linear layout. Also, you might not be seeing the textviews at all because the overall layout might be too tall.
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="#drawable/logo" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageButtonProjet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/projet" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageButtonProjet"
android:layout_marginLeft="32dp"
android:text="Projects"
android:textColor="#color/text_color" >
</TextView>
<ImageButton
android:id="#+id/imageButtonWorkitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/workitem" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageButtonWorkitem"
android:layout_marginLeft="62dp"
android:text="WorkItem"
android:textColor="#color/text_color" >
</TextView>
<ImageButton
android:id="#+id/imageButtonUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="#drawable/user" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageButtonUser"
android:layout_marginBottom="28dp"
android:layout_marginLeft="65dp"
android:text="Users"
android:textColor="#color/text_color" >
</TextView>
</LinearLayout>