ImageView on top of another imageview in Android - android

I am having a navigation drawer (sliding menu) with header set in my app. I am trying out the following for the headerView.xml
I am setting a background image to the relativeLayout from a particular URL. Instead I would like to have ImageView like below:
By doing this I can use picasso library even for background image that I receive from an URL. This way the image loading is faster I don't need to save the background to any sd card etc.
Here is what I have right now:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LayoutforbgImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/LinearLayoutforImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
tools:ignore="RtlSymmetry,RtlHardcoded" >
<ImageView
android:id="#+id/imageforprofile"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/profilepic" />
</LinearLayout>
<TextView
android:id="#+id/textforprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="16dp"
android:text="My Name My Name"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/textforprofileemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textforprofile"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:text="myname#abc.com"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
</RelativeLayout>
I am setting background image to layout for: LayoutforbgImage
using:
headerLayout = (RelativeLayout) header.findViewById(R.id.LayoutforbgImage );
BitmapDrawable background = new BitmapDrawable(decodeBase64(coverimage));
headerLayout.setBackgroundDrawable(background);
headerprofileimage = (ImageView) header.findViewById(R.id.imageforprofile);
Picasso.with(this).load(profileImage).placeholder(R.drawable.profilepic).error(R.drawable.profilepic).into(headerprofileimage);
How do I create the ImageView for background image so that it fits perfectly in the layout specified like above?

Try this layout i hope it will help you
<?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:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/top_header_bg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginRight="20dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

hi try the following code it will help you i didn't make any changes. i simply add an ImageView to your layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LayoutforbgImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="#+id/your_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/top_bar" />
<LinearLayout
android:id="#+id/LinearLayoutforImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
tools:ignore="RtlSymmetry,RtlHardcoded" >
<ImageView
android:id="#+id/imageforprofile"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/images12" />
</LinearLayout>
<TextView
android:id="#+id/textforprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="16dp"
android:text="My Name My Name"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/textforprofileemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textforprofile"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:text="myname#abc.com"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
</RelativeLayout>

Try this way hope it will solve your problem
<?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" >
<RelativeLayout
android:id="#+id/topBarRelative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/imageHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:src="#drawable/right_top_bg" />
<ImageView
android:id="#+id/imageforprofile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="9dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="9dp"
android:layout_toRightOf="#+id/imageforprofile"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textforprofile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:text="My Name My Name"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="#+id/textforprofileemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="myname#abc.com"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/topBarRelative"
android:layout_margin="8dp"
android:background="#drawable/content_bg"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
Screen shot from Eclipse

Related

Image, text/text and image in Android

I am trying to get the following design. Consider that it is a list item.
But my following design, it does not give me that design.The textviews come on the top of left image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_person_black_24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="#+id/userimage" />
<TextView
android:text="Text1"
android:layout_toRightOf="#id/userimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/username"/>
<TextView
android:text="Text2"
android:layout_below="#id/name"
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_keyboard_arrow_right_black"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout >
Instead of a LinearLayout use a RelativeLayout, and for the TextViews use:
android:layout_toRightOf="#id/userimage" and
android:layout_alignTop="#id/userimage" or
android:layout_alignBottom="#id/userimage"
Here you go:
<?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="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal">
<ImageView
android:id="#+id/userimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_person_black_24dp"
tools:background="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="#id/userimage"
android:layout_toEndOf="#id/userimage"
android:layout_toStartOf="#id/arrow"
android:orientation="vertical">
<TextView
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
tools:text="Text1" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
tools:text="Text2" />
</LinearLayout>
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_keyboard_arrow_right_black"
tools:background="#mipmap/ic_launcher" />
</RelativeLayout>
Try to play with different layouts when you have time, it will help you greatly in the future.
Edit:
Better solution for centering TextViews.
Your problem in text2 use it , it would work
<TextView
android:text="Text2"
android:layout_below="#id/username"
android:layout_toRightOf="#id/userimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip" >
<ImageView
android:id="#+id/userimage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO"
android:src="#drawable/ic_person_black_24dp" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="6dip"
android:contentDescription="TODO"
android:src="#drawable/ic_keyboard_arrow_right_black" />
<TextView
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_above="#id/secondline"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/userimage"
android:layout_toLeftOf="#id/icon"
android:singleLine="true"
android:gravity="center_vertical"
android:text="Example username"
android:textSize="16sp" />
<TextView
android:id="#+id/secondline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/userimage"
android:layout_toLeftOf="#id/icon"
android:singleLine="true"
android:text="Description"
android:textSize="12sp" />
</RelativeLayout>
I used some dp sizes that you did not use and added a few other things, but I guess you can change it so that it suits your desire. I did try use the same names as you did. Overall this should work if you tweak it a bit.

Insert image as background set it bottom right corner inside Linear Layout

I have activity based of vertical LinearLayout
Something like that:
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="#+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="#layout/title_bar_fragment" />
<ImageView
android:background="#drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="#style/MyTextViewLabel"
android:text="#string/str_under_logo" />
<TextView android:id="#+id/tv_applicationVersion"
style="#style/MyTextViewLabel.Black.Data"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="#style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/blue_end"
android:padding="5dp">
<TextView style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="#color/white"/>
<TextView android:id="#+id/tv_serial_number"
style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="#+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="#color/transparent"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I want to place image as background but it needs to go into right bottom corner. How do I do that?
EDIT:
I tried to do it like this, by wrapping into FrameLayout and setting gravity for image but it doesn't put image to the bottom and I still need to know how to align it to the right
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/img_background"
android:layout_gravity="bottom"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="#+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="#layout/title_bar_fragment" />
<ImageView
android:background="#drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="#style/MyTextViewLabel"
android:text="#string/str_under_logo" />
<TextView android:id="#+id/tv_applicationVersion"
style="#style/MyTextViewLabel.Black.Data"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="#style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/blue_end"
android:padding="5dp">
<TextView style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="#color/white"/>
<TextView android:id="#+id/tv_serial_number"
style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="#+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="#color/transparent"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
I suggest you to wrap it into RelativeLayout.
Then in your ImageView tag add android:layout_alignParentBottom="true" and android:layout_alignParentRight="true" to align it at the bottom right corner.
<?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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/img_background"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="#+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="#layout/title_bar_fragment" />
<ImageView
android:background="#drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="#style/MyTextViewLabel"
android:text="#string/str_under_logo" />
<TextView android:id="#+id/tv_applicationVersion"
style="#style/MyTextViewLabel.Black.Data"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="#style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/blue_end"
android:padding="5dp">
<TextView style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="#color/white"/>
<TextView android:id="#+id/tv_serial_number"
style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="#+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="#color/transparent"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>

Fetch imageview to all the screen in relativelayout between buttons and edittext

I have the below XML relativelayout... I need help to make the image always fetch to all the screen but between above name ju and below buttons.
the following ImageView parameter make the image centered.
<?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"
android:orientation="vertical" >
<TextView android:id="#+id/nameview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFE0"
android:paddingBottom="10dp"
android:paddingTop="14dp"
android:paddingLeft="45dp"
android:fontFamily="Arial"
android:textSize="18sp"
android:textStyle="bold"
android:text="Ju" />
<ImageView android:id="#+id/SingleView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/nameview"/>
<Button
android:id="#+id/funnyBtn"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="10dp"
android:layout_below="#+id/SingleView"
android:layout_alignParentLeft="true"
android:src="#drawable/smileclk"
android:background="#drawable/smileclk"
android:layout_marginLeft="25dp"
android:text="" />
<Button
android:id="#+id/test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/SingleView"
android:layout_toRightOf="#+id/funnyBtn"
android:layout_marginLeft="15dp"
android:text="test1" />
<Button
android:id="#+id/test2Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/SingleView"
android:layout_toRightOf="#+id/comment"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:text="test2" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="20dp"
android:layout_below="#+id/test2Btn"
android:background="#ff00ff00" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="20dp"
android:padding="10dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculation" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ffffff" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
this is my result for now
this is my desire output
As murtaza mentioned adding android:scaleType="fitXY" helped
<ImageView android:id="#+id/SingleView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_below="#id/nameview"/>

Unable create layout with image and text for listvieitem

<?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="90dip"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="#+id/rowcontact_txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="Usama Sadiq"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/rowcontact_imgLocationIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_below="#+id/rowcontact_txtName"
android:layout_marginLeft="10dip" />
<TextView
android:id="#+id/rowcontact_txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rowcontact_txtName"
android:layout_toRightOf="#+id/rowcontact_imgLocationIcon"
android:text="Dubai"
android:textColor="#898788"
android:textSize="11.5dp" />
<ImageView
android:id="#+id/rowcontact_imgIcon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignBottom="#+id/rowcontact_txtLocation"
android:layout_marginLeft="94dp"
android:layout_toRightOf="#+id/rowcontact_txtName" />
</RelativeLayout>
</RelativeLayout>
i am trying to create layout for list-view item but i am not able to fix position of image and text with three different Position please tell me solution how to fix it. i have to create listviow item i am able to display list-view but like given screen
i have all icon an all but am unable to fix potion of text-view and image view like given screen
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="2"
android:layout_margin="5dp"
>
<TextView
android:id="#+id/rowcontact_txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Usama Sadiq"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/rowcontact_txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rowcontact_txtName"
android:layout_toRightOf="#+id/rowcontact_imgLocationIcon"
android:text="Dubai"
android:textColor="#898788"
android:textSize="11.5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Using layout as a sublayout & accessing it programatically in android?

I have a layout called thumb_unit.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_height="240dp"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/thumbImage"
android:layout_marginLeft="10dp"
android:layout_width="160dp"
android:layout_height="220dp"
android:scaleType="fitXY"
android:src="#drawable/app_icon"
android:layout_marginTop="20dp"/>
<LinearLayout
android:layout_width="160dp"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="vertical" >
<TextView
android:id="#+id/issueName"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Summer 2012"
android:textSize="18dp"
android:layout_marginLeft="6dp"
/>
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="151dp"
android:layout_marginLeft="6dp"
android:text="Description"
android:textSize="14dp"
android:textStyle="italic" />
<Button
android:id="#+id/view_download"
android:layout_marginTop="5dp"
android:layout_width="80dp"
android:layout_marginLeft="5dp"
android:layout_height="30dp"
android:text="View"
android:textSize="14dp"
android:textColor="#drawable/push_button_text_color"
android:background="#drawable/push_button"
android:layout_marginBottom="40dp"
/>
</LinearLayout>
</LinearLayout>
and another layout called grid_unit.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="170dp"
android:layout_height="130dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/thumbImage"
android:layout_width="77dp"
android:layout_height="105dp"
android:src="#android:drawable/ic_menu_gallery"
android:layout_marginTop="10dp"
/>
<LinearLayout
android:layout_width="73dp"
android:layout_height="120dp"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
>
<TextView
android:id="#+id/issueName"
android:layout_width="77dp"
android:layout_marginTop="5dp"
android:layout_height="30dp"
android:text="South Louisiana PnK"
android:layout_marginLeft="3dp"
android:textSize="11dp"
android:textStyle="bold" />
<TextView
android:id="#+id/productName"
android:layout_marginTop="5dp"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_marginLeft="3dp"
android:text="South Louisiana PnK"
android:textSize="9dp" />
<Button
android:id="#+id/viewButton"
android:layout_width="70dp"
android:layout_height="20dp"
android:text="View"
android:textSize="9dp"
android:textColor="#drawable/push_button_text_color"
android:background="#drawable/push_button"
android:layout_marginTop="5dp"
android:layout_marginLeft="3dp"
/>
</LinearLayout>
</LinearLayout>
and now finally, I have main activity_main.xml, I want to use the combination of these as
<?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="wrap_content"
android:layout_height="440dp"
android:orientation="vertical"
tools:context="com.mirabel.activities.MainActivity" >
<include layout="#layout/thumb_unit" android:id="#+id/main_thumb"/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<include layout="#layout/grid_unit" android:id="#+id/left_grid"/>
<include layout="#layout/grid_unit" android:id="#+id/right_grid"/>
</LinearLayout>
</LinearLayout>
sublayout in the activity_main.xml and programatically I want to set the image, text for all these things. How to do that?
You can do it in the Activity file for activity_layout.xml in the following way:
View view = findViewById(R.id.left_grid);
ImageView image = view.findViewById(R.id.thumbImage);
image.setBackgroundResource(R.id.image)); //or whatever you wish to set
TextView text = view.findViewById(R.id.issueName);
text.setText("Whatever text you want to set);
In this way, you can access all the Views in the included layout.

Categories

Resources