here is my xml file for showing images in design view.i added the picture in drawable folder.but its not working.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:src="#drawable/german"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/imageView2"
android:src="#drawable/german"
android:layout_weight="1"/>
</LinearLayout>
Try This
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:src="#drawable/german"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/imageView2"
android:src="#drawable/german"
android:layout_weight="1"/>
</LinearLayout>
Change your android:layout_height of LinearLayout to wrap_content.View with 0dp height will not show.
Here is the solution,
<?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="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Happy to Help and Happy Coding...
You have to do like this way:
<?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="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Surely it would works.
Related
I'm trying to have 3 sections under each others using LinearLayout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ImageEditing">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<com.google.android.gms.ads.AdView
android:id="#+id/adViewOfEditing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/imageEditView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_margin="0dp"
android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#123456"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/qa_gallery" />
<ImageView
android:id="#+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/qa_camera" />
<ImageView
android:id="#+id/erase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/qa_trash" />
<ImageView
android:id="#+id/crop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/qa_view_post" />
<ImageView
android:id="#+id/undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/qa_reply_comment" />
</LinearLayout>
</LinearLayout>
all seems to be fine , but the Image of the middle section , it's not matching the parent size, it has gaps at left&right, where the other sections are fine! , what am doing wrong here?
Edit: Screenshot
Use android:adjustViewBounds="true"
This is what eventually fixed it properly for me. You don't need scaleType.
I tried your layout and everything is working perfect :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#343434"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/imageEditView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_margin="0dp"
android:background="#654321"
android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#123456"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/common_ic_googleplayservices" />
<ImageView
android:id="#+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/common_ic_googleplayservices" />
<ImageView
android:id="#+id/erase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/common_ic_googleplayservices" />
<ImageView
android:id="#+id/crop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/common_ic_googleplayservices" />
<ImageView
android:id="#+id/undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/common_ic_googleplayservices" />
</LinearLayout>
And screenshot :
I faced same problems too but
Try to use
android:background="";
instead of
android:src="";
I need to do an layout in which 4 images are shown in a box in different sizes using XML.
The box is a linearLayout with a fixed height 300dp and fill_parent in the width. It is not a Requirement to do this using a LinearLayout.
I tried to do it using weights and weightsum, but there was no success.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_margin="10dp" >
<ImageView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="#drawable/image1" />
<ImageView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="#drawable/image2" />
<ImageView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:src="#drawable/image3" />
<ImageView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:src="#drawable/image4" />
</LinearLayout>
Here an example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:layout_weight="1" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView2"
android:layout_weight="1" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView3"
android:layout_weight="1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView4"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
In my android application I want to design the layout like blow
I have the four separate images like below
please anyone help me in this how to design this layout. Thanks in advance
You can try this..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image2" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image4" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image3" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
// try this
<?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="match_parent"
android:padding="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
To achieve this you need to have 5 set of image. One is default and other four will be like
So onclick of the image you need to switch the image with animation.
Is there a way to get the images touching like in this image without guessing the heights of each horizontal LinearLayout?
As you can see from my XML i had to guess the LinearLayout heights at 144dp to get this effect, is there a better way that would work on different screen sizes?
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="144dp" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_sport" />
<ImageView
android:id="#+id/ImageView02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_science" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="144dp"
android:layout_gravity="fill_horizontal" >
<ImageView
android:id="#+id/imageView03"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_science" />
<ImageView
android:id="#+id/imageView04"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_sport" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout03"
android:layout_width="match_parent"
android:layout_height="144dp"
android:layout_gravity="fill_horizontal" >
<ImageView
android:id="#+id/ImageView05"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_sport" />
<ImageView
android:id="#+id/ImageView06"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_science" />
</LinearLayout>
</LinearLayout>
If possible I would prefer to be able to do it in XML. The images are square so they have to fill the width and still be in proportion. I can almost do it with fitXY but that just stretches their width and not their height.
You should use a GridView instead of many LinearLayouts.
If you want to keep your code, update this :
Your main layout should have this property :
android:layout_height="match_parent"
The other "Layout Wrappers" should have :
android:layout_height="wrap_content"
android:orientation="horizontal"
Your imageView should have :
android:layout_height="wrap_content"
Are you working only with square images ?
I updated your code and didn't try it, but it should work :
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_sport" />
<ImageView
android:id="#+id/ImageView02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_science" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_science" />
<ImageView
android:id="#+id/imageView04"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_sport" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ImageView05"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_sport" />
<ImageView
android:id="#+id/ImageView06"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_science" />
</LinearLayout>
</LinearLayout>
Whilst the images aren't perfectly square (although its quite unnoticeable) i managed to solve this problem by using 2 Vertical LinearLayouts instead of 3 Horizontal ones and using ScaleType=fitXY to fill the remaining gaps, leaving me with this:
From the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="3" >
<ImageView
android:id="#+id/ImageView03"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/ic_science" />
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/ic_sport" />
<ImageView
android:id="#+id/ImageView02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/ic_science" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="3" >
<ImageView
android:id="#+id/ImageView04"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/ic_sport" />
<ImageView
android:id="#+id/imageView03"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/ic_science" />
<ImageView
android:id="#+id/imageView04"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/ic_sport" />
</LinearLayout>
</LinearLayout>
how do i align three imageview horizontally like this image http://imgur.com/isvfTqZ how to make this typelayout. it is linearlayout or Relativelayout help me???
How can I make vertical combination of imageview and textview horizontally...?
<?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="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:background="#F9F939"
android:src="#drawable/ic_launcher"
android:layout_toLeftOf ="#+id/imageView6"
android:layout_centerInParent="true"
android:padding="15dp" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#54F71D"
android:src="#drawable/ic_launcher"
android:layout_centerInParent="true"
android:padding="15dp"
android:layout_margin="10dp" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1DF7AB"
android:src="#drawable/ic_launcher"
android:layout_centerInParent="true"
android:layout_toRightOf="#+id/imageView6"
android:padding="15dp" />
</RelativeLayout>
Use LinearLayout with orientation = horizontal
You can do like this...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="#null"
android:text="#string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="#null"
android:text="#string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgHome2Imag3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="#null"
android:text="#string/hello_world" />
</LinearLayout>
</LinearLayout>
use the property of android:layout_toLeftOf="+#id/img1" or android:layout_toRightOf="+#id/img1" if you want to use Relative layout. Otherwise its alright to go with the LinearLayout.