Android ImageView alignment in LinearLayout - imageview

I have a simple android app. In an activity I added LinearLayout(horizontal. There I put three different ImageView objects. I want them to be : one on left, one in center, one on right side.
This is xml code:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/javtokas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_lefthorizontal="true"
android:src="#drawable/javtokas" />
<ImageView
android:id="#+id/jankunas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerhorizontal="true"
android:src="#drawable/jankunas" />
<ImageView
android:id="#+id/lipkevicius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_righthorizontal="true"
android:src="#drawable/lipkevicius" />
</LinearLayout>
I tried a bunch of different options but no one worked well. How can I achieve what I want?

You are looking for
android:layout_weight
All your image view should have
android:layout_width='0dp'
android:layout_weight='1'

Related

Combining two text views in single line

I want to align text view as mentioned below in my android application
totally two lines
in first line one text view layout weight 2
in second line one text view layout weight 2
the third text view combining both lines and the layout weight 1 and text alignment center
anyone please help me to get fixed this in my android application
the xml layout
<LinearLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/itemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:importantForAutofill="no"
android:padding="15dp"
android:fontFamily="#font/bold"
android:textSize="20sp"
android:textColor="#color/black"
android:textAlignment="center"
tools:ignore="Deprecated,TouchTargetSizeCheck,DuplicateSpeakableTextCheck"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/eancode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:textAlignment="center"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/rate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:importantForAutofill="no"
android:selectAllOnFocus="true"
android:padding="25dp"
android:fontFamily="#font/bold"
android:textSize="40sp"
android:textAlignment="center"
android:textColor="#color/black"
tools:ignore="Deprecated,TouchTargetSizeCheck,SpeakableTextPresentCheck" />
</LinearLayout>
</LinearLayout>
thank you

Android - Displaying an additional layout underneath an ImageView when using Picasso's fit() and centerInside()

Below is an ImageView that can't 'wrap_content' on the height and width as it is displaying the image using Picasso's fit() and centerInside() attributes.
Due to this, I have to either set a height in dp or state 'match_parent'. If I set a specific height in dp my Button will display but this isn't ideal for different sizes screens of course. If I set 'match_parent' the ImageView fills the rest of the screen and I can't display my Button underneath the ImageView.
Does anyone know of a way to nest my ImageView in some way so I can display my final Button?
Also, I can't work out how to align my picture of the top of the ImageView, please help with this as well if you can.
main_activity.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackground">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize" />
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:padding="10dp">
<Button
android:id="#+id/button_kitty"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_kitty" />
<Space
android:id="#+id/space"
android:layout_width="10dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_cat"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_cat" />
</LinearLayout>
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/button_layout"
android:layout_marginBottom="17dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="4dp"
android:adjustViewBounds="true" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/button_layout"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:indeterminate="true"
android:visibility="invisible" />
<Button
android:id="#+id/button_facebook"
style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:layout_centerHorizontal="true"
android:gravity="center" />
ActivityMain.java
#Override
public void onResponse(Call<KittyCatModel> call, Response<KittyCatModel> response) {
KittyCatModel model = response.body();
String url = model.getSource();
Picasso.with(this)
.load(url)
.fit()
.centerInside()
.into(imageView, this);
}
On Picasso's github, there's a thread regarding fit() not working when an imageView has adjustViewBounds set to true. Remove either one and see how it goes (I'm doing this from mobile, so can't test it before answering, sorry).
Here's a link to that thread:
https://github.com/square/picasso/issues/425
That thread links to another thread on Picasso's git regarding creating a custom imageView to make this work the way you want
Here's a link to that thread:
https://github.com/square/picasso/issues/457
Had some offline assistance with this issue, answer is:
This is nothing to do with Picasso, it is just an XML issue.
The ImageView and ProgressBar needed to be in a RelativeLayout within a
LinearLayout so I could apply layout_weight=“1” to that RelativeLayout.
This allowed me to “match_parent” on my ImageView width and height so
the image fills its layout but doesn’t hide the bottom button.
Hope that helps somebody else in the future.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/color_background"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize" />
<LinearLayout
android:id="#+id/button_layout_generate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:orientation="horizontal"
android:padding="12dp">
<Button
android:id="#+id/button_kitty"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_kitty" />
<Space
android:id="#+id/space"
android:layout_width="10dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_cat"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_cat" />
</LinearLayout>
<RelativeLayout
android:id="#+id/image_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#id/button_layout_generate"
android:layout_weight="1"
android:paddingRight="16dp"
android:paddingLeft="16dp">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
<LinearLayout
android:id="#+id/button_layout_facebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:orientation="horizontal"
android:padding="12dp">
<Space
android:id="#+id/space_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<Button
android:id="#+id/button_facebook"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:layout_weight="1"
android:enabled="false"
android:gravity="center"
android:text="#string/button_facebook" />
<Space
android:id="#+id/space_right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>

Android LinearLayout does not left align contents

I want to create a horizontal line of small images thumbnails on top of the display. They should be lined up from left to write (all floated left). When you click on a thumbnail, its bigger version should be displayed below this line. I decided to go with a horizontal LinearLayout (see the one with ID = galleryLayout). It should be a LinearLayout because I want to use it later within a HorizontalScrollView. Here is my layout code:
<?xml version="1.0" encoding="utf-8"?>
<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:background="#ffffef3a"
android:orientation="vertical"
tools:context=".Gallery01">
<LinearLayout
android:id="#+id/galleryLayout"
android:orientation="horizontal"
android:gravity="left"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="#ffff3e34">
<ImageView
android:src="#drawable/pic02"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:id="#+id/image1"
android:scaleType="fitXY"
android:layout_width="320dp"
android:layout_height="320dp" />
</LinearLayout>
But the problem is that the image is displayed in the center of the layout as you can see here:
As you can see the gravity in the LinearLayout does not work and the image is displayed in the center horizontally. The gravity of the ImageView itself does not work as well (that is just an attempt to make it work!).
Do you guys have any idea what I am doing wrong? Thank you for help!!
I could manage to resolve the problem step by step. Here the results:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="120dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="left"
android:background="#000000"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:src="#drawable/pic01"
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="10dp"
android:background="#000000" />
<ImageView
android:src="#drawable/pic05"
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="10dp"
android:background="#000000" />
<ImageView
android:src="#drawable/pic03"
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="10dp"
android:background="#000000" />
<ImageView
android:src="#drawable/pic04"
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="10dp"
android:background="#000000" />
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:src="#drawable/pic01"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
It works perfectly :-)

why my sign up page not coming same as all the mobiles in android?

My actual task is to design a sign up page is like this.
https://docs.google.com/file/d/0B_c-SDSO63obTXdXMm4yZmRkUDQ/edit?usp=sharing
I did some coding that is
<LinearLayout
android:id="#+id/detailstenter"
android:layout_height="fill_parent"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_weight="370"
android:weightSum="122">
<EditText
android:id="#+id/emailidenter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="john#clite.com"
android:singleLine="true"
android:ellipsize="end"
android:background="#drawable/email_up"
android:drawableLeft="#drawable/usericon_two"
android:textColor="#000000"
android:textStyle="bold" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint=".........."
android:inputType="textPassword"
android:singleLine="true"
android:ellipsize="end"
android:background="#drawable/email_down"
android:drawableLeft="#drawable/usericon_two"
android:textColor="#000000"
android:textStyle="bold" >
<requestFocus />
</EditText>
</LinearLayout>
But when i running in the nexus 7 the out is changed.
this is https://docs.google.com/file/d/0B_c-SDSO63obT1JGSlBjMHZSbnM/edit?usp=sharing
so please give some suggestions how can i do that task to get the output same as all the mobiles and tablets.
I tried image view+edit text with that background. But that is also not coming properly.
Please give some idea to this task.
thank you
shankar
clite

set ImageView above Textview

I just want to do a very simple think :
I want to put an ImageView on full screen with just a simple TextView on his Bottom, not Over but just on his bottom..
I tried some combination but nothing worked fine..
Here is my current basic XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:src="#drawable/creditview" />
<RelativeLayout
android:id="#+id/layoutimgset"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This spot is for Ad"
android:textStyle="bold"
android:textColor="#color/black"
android:background="#color/white" />
</RelativeLayout>
</LinearLayout>
This only show the ImageView..
Try to use for your ImageView this:
android:layout_weight="1"
In this case you don't need RelativeLayout.
Or put all to RelativeLayout and use
android:layout_below="#+id/imgset"
for your TextView

Resources