Ok, so here is where I sit: I cannot for the life of me figure out why the image to the left will not display. It should be the same image as the one to the right of notifications. I have gone over it a few different ways and cannot get that image to display on the left side of notifications.
<LinearLayout
android:orientation="vertical"
android:id="#id/notificationCart"
android:background="#000000"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="#dimen/status_bar_expanded_notification_category_height">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_gravity="left|center"
android:layout_toLeftOf="#id/latestNotificationText"
android:layout_width="wrap_content"
android:layout_height="#dimen/tw_close_handle_height"
android:src="#drawable/tw_quick_panel_plnm_setting_dv"
android:scaleType="fitXY"/>
<TextView
android:textSize="#dimen/status_bar_expanded_notification_category_text_size"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:textColor="#color/notification_category_color"
android:gravity="center"
android:id="#id/latestNotificationText"
android:paddingLeft="10.0dip"
android:paddingRight="10.0dip"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/status_bar_latest_events_title"/>
<ImageView
android:layout_gravity="right|center"
android:layout_toRightOf="#id/latestNotificationText"
android:layout_width="wrap_content"
android:layout_height="#dimen/tw_close_handle_height"
android:src="#drawable/tw_quick_panel_plnm_setting_dv"
android:scaleType="fitXY"/>
</RelativeLayout>
</LinearLayout>
If you need to place two images left and right of the TextView
why do you need the RelativeLayout?
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
....>
<ImageView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout />
<LinearLayout />
Note that the parent FrameLayout has it's width set to match_parent.
Related
What I am trying to do is wrap the textview around the imageview so that way the text isn't just on the left or right side of the image. Is it possible to do this through XML? As it is a popup dialog with a picture, so doing it through code will be a pain as it is multiple images depending on what they click. See picture for example.
<?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="fill_parent"
android:orientation="vertical"
android:background="#android:color/background_light">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="#android:color/darker_gray">
>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Close" />
<ImageView
android:id="#+id/IV1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/IV1"
android:layout_below="#+id/dismiss"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/TV15"
android:id="#+id/TV15"
android:layout_below="#+id/dismiss"
android:layout_toRightOf="#+id/IV1"
android:layout_toEndOf="#+id/IV1"
android:paddingLeft="5dp"
android:paddingTop="5dp"/>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Use FrameLayout. Change the order of ImageView and TextView to set what should come top of the other.
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/menu_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:lines="1"
android:text="this is my sample" />
</FrameLayout>
Here is my Code
<LinearLayout android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_height="wrap_content">
<RadioButton android:id="#+id/preference_question_optionTwo" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
Now here when i apply android:layout_weight="1" on LinearLayout the image does not appear.Without this property image is displayed.
What i want is to divide the layout into two parts. Both parts containing the same code above i.e a radio button and besides that an image and a text
Update This is how i want it
This is what i am getting as output
You didn't share the rest of your code or your intentions on how you want to divide the screen into two: vertically or horizontally.
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout android:layout_width="0dp"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_weight="1" >
<RadioButton android:id="#+id/preference_question_optionOne" android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:layout_width="0dp"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_weight="1" >
<RadioButton android:id="#+id/preference_question_optionTwo" android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
It seems that you got confused by the weight concept. It will be more clear this way, I guess. You should divide the parent's width or height according to those weights. Also don't forget to use it with 0dp.
If you want to divide the parent vertically, use this combination:
android:layout_height="0dp"
android:layout_width="match_parent" <!--or wrap_content-->
android:layout_weight="x"
and for horizontally
android:layout_height="match_parent" <!--or wrap_content-->
android:layout_width="0dp"
android:layout_weight="x"
The layout weight property is for elements within a linear layout. You should give each half of the screen the same weight and put them both within a linear layout.
Here's what you need:
<LinearLayout android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent">
<!-- first half -->
<LinearLayout android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_height="wrap_content">
<RadioButton android:id="#+id/preference_question_optionTwo" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
<!-- first half, same weight as first half -->
<LinearLayout android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_height="wrap_content">
<RadioButton android:id="#id/preference_question_optionTwo" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
If You need to divide Your layout in two parts with the same width, you need to set childs width to fill_parent and set the same wieght (> 1) to children.
For example:
<LinearLayout android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<RadioButton android:id="#+id/preference_question_optionTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
I am trying to make a layout with an image on the left side, then a text, and two images on the right side. I show you how it likes now:
I want to put the two right icons on the right side, next to the limit of the screen. Then, if you see, when the text has more than one line, the two icons disappear and when the text is too long the icons are very small. I want a static space for every one of the icons.
<?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="wrap_content"
android:orientation="horizontal"
android:padding="6dip">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="6dip"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:focusable="false"
android:focusableInTouchMode="false"
android:contentDescription="#string/cdLogo" />
<LinearLayout
android:id="#+id/lista2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:paddingRight="20dip"
android:layout_toRightOf="#id/icon"
android:layout_marginRight="30dip">
<TextView
android:id="#+id/tituloevento"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left"
android:textStyle="bold" />
<TextView
android:id="#+id/distritoevento"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left"
android:textSize="12sp"/>
<TextView
android:id="#+id/coorp0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/coorp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/esgratis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/caracteristicas"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_toRightOf="#id/lista2"
android:layout_alignParentRight="true">
<ImageView
android:id="#+id/iconoMapa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/cdTieneCoor"
android:layout_weight="0.5"/>
<ImageView
android:id="#+id/iconoGratis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/cdGratisPago"
android:layout_weight="0.5"/>
</LinearLayout>
</RelativeLayout>
I suggest you to use a LinearLayout as the top container, and distribute the space of the child elements with weight attributes. When using weight, you must set layout_width to 0dp for horizontal layouts or layout_heigth to 0dp for vertical layouts.
For example:
<?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="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5" >
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" >
</LinearLayout>
</LinearLayout>
I have a ImageView, the image is loaded from the net and can vary in width.
Below I have a TextView with a description of the image. I want the TextView to be exactly as wide as the ImageView.
My try was this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="#style/SmallTextGray" />
</LinearLayout>
which somehow works as the TextView's width is set accoring to that of the ImageView, but the TextView end after 2 lines:
I know I could set the TextView's width programmatically after I know the image's width, but is there also a way to do it in the XML layout?
I don't know if it will work, but try doing in your code, after load the image:
textView.setWidth(imageView.getDrawable().getIntrinsicWidth());
With a small change of layout: replace LinearLayout with a RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/iv"
android:layout_alignRight="#+id/iv"
android:layout_below="#+id/iv"
android:layout_marginTop="8dp"
android:gravity="center_horizontal"
android:textAppearance="#style/SmallTextGray" />
</RelativeLayout>
This way the TextView is always below imageView and its bounds are aligned to imageViews
You can use weight like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
You can use the wight property in xml and give equal weight to both imageview and textview. then both size will be equal
In your case do this:
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_horizontal" />
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:textAppearance="#style/SmallTextGray" />
</LinearLayout>
Try This.This will work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:typeface="monospace" />
</LinearLayout>
</LinearLayout>
This works for me:
<?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_gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/controller"
android:layout_gravity="center_horizontal"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:text="asdasdasasasdasdasdasdasdasdasdadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsdasdasdasdsadsadsadasdasdsadsadsadasdasdasdasdasdasddasdasdasdasdasdasdasdsadasdasdasdasdasdasdsadasdasdsa..."/>
</TableRow>
</TableLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
What I just want to do it to put some texts in the screen, together with a border that I'm doing(this border will be in the entire screen.)
The problem is that the LinearLayout is adding some texts to outside of the screen, and this I cannot understand why. Why the LinearLayout cannot just keep the elements in the screen size, even if will be very small sizes.
Take a look:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#color/White">
<ImageView android:layout_height="wrap_content"
android:minHeight="2px" android:maxHeight="2px"
android:layout_gravity="top" android:src="#drawable/horizontal_bar"
android:scaleType="fitXY" android:layout_weight="1"
android:layout_width="fill_parent" />
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<ImageView android:src="#drawable/vertical_bar"
android:minWidth="2px" android:maxWidth="2px" android:scaleType="fitXY"
android:layout_gravity="left" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="testing" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="15px"
android:textStyle="bold" android:textColor="#color/grey"
android:textSize="20px" android:layout_weight="1"
android:layout_gravity="center_horizontal|center" />
<TextView android:text="blablabla" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="15px"
android:textStyle="bold" android:textColor="#color/grey"
android:textSize="20px" android:layout_weight="1"
android:layout_gravity="center_horizontal|center" />
<TextView android:text="0000" android:id="#+id/number"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_gravity="left" android:textStyle="bold"
android:textColor="#color/green" android:textSize="20px"
android:layout_weight="1" />
<ImageView android:src="#drawable/vertical_bar"
android:minWidth="2px" android:maxWidth="2px" android:scaleType="fitXY"
android:layout_gravity="right" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_weight="1" />
</LinearLayout>
<ImageView android:layout_height="wrap_content"
android:minHeight="2px" android:maxHeight="2px"
android:layout_gravity="top" android:src="#drawable/horizontal_bar"
android:scaleType="fitXY" android:layout_weight="1"
android:layout_width="fill_parent" />
</LinearLayout>
Where horizontal_bar is a image with 6x4 and vertical_bar is a image with 4x6.
This image needs to be stretch to be able to became a border.
Any idea why the LinearLayout is going out of the screen size?
Your
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
should have vertical orientation.