[Second Edited]
I found where problem is. But i dont know why its doing. It cant be margin on LinearLayout (or just marginLeft). Does anybody know why it cant have ?
[EDITED]
Hello i have xml file in layout like bellow.And iam adding TextViews from any xml layout to horizontal LinearLayout. This layout structure is given and i cant change it.
And last added TextView is streching always verticaly. I dont know why i am in tottaly despair. Too many hours i was try* that but without no idea. I know just its not in programicaly adding TextViews ..
If some body know why its doing i will be thankful.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/back_border"
>
<RelativeLayout
android:id="#+id/manager_view_table_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<LinearLayout
android:id="#+id/layout_for_textViews"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6px"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:background="#drawable/back_border"
>
<!-- horizontal layout, HERE IAM ADDING TEXTVIEWS -->
</LinearLayout>
</RelativeLayout>
<!--What is here its no important
because, there is RelativeLayout with alignBellow relative layout before -->
</RelativeLayout>
and TextView witch iam addig to LinearLayout:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:paddingRight="7px"
android:paddingLeft="7px"
android:paddingTop="3px"
android:paddingBottom="3px"
android:layout_marginLeft="5px"
android:gravity="center_horizontal"
android:background="#drawable/background_table"
android:textColor="#330033"
android:text="Some text"
/>
Try to replace the android:layout_margin="6px" from the LinearLayout by android:padding="6px".
I think this will solve your problem. I mean the new LInearLayout should be like this:
<LinearLayout
android:id="#+id/layout_for_textViews"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6px"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:background="#44ff435f"
>
I am confused with your three layouts. Wat's the porpose of all thses nested layouts, try to recreate the text views with a single relative layout, and use the android:layout_above and android:layout_below for placing the text views.
First of all you need to refactor this code.
You might want to use actual ListView to create repeated elements.
and why is xmlns:android="http://schemas.android.com/apk/res/android" declared thrice in this xml code, when it is actually required just once at top root element.
Even with this layout to solve your problem, if other things are not working a nice idea would be to switch to Graphic layout(bottom tab in eclipse when on .xml file) and manually try to set the third TextView (not listview) height manually, you can observe the changes then and finalize them accordingly..
Related
So i`m coding this custom listView Adapter. The adapter AXML looks like this:
The problem is that when i compile and run in emulator, the ListView item turns into this :
Can anyone help me figure out what is happening? Maybe help me fix it?. If you need any code let me know.
UPDATE: AXML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="ABC 232"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/shopName"
android:textColor="#3c3c3c"
android:textSize="22dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:weightSum="1">
<TextView
android:text="~800m away"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/distance"
android:layout_marginLeft="0.0dp"
android:textColor="#3c3c3c"
android:layout_weight="0.5"/>
<TextView
android:text="Total: 12.45 RON"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/total"
android:layout_gravity="right"
android:layout_marginLeft="22.0dp"
android:textColor="#3c3c3c"
android:layout_weight="0.5"/>
</LinearLayout>
</LinearLayout>
Please change all the text views width and height attribute to wrap_content. Specially for text view for shopName.
You can also remove linearLayout1, linearLayout3 and linearLayout4. Since they added noting important to your view.
You do not need to encapsulate each TextView in a LinearLayout. If you desire padding around the font, the TextView has padding attributes that will achieve the same effect in a cleaner manner.
If you clean up the code in this way, the issue with views not appearing may appear clearer.
It could be much simpler, use relative layout and align all three text one another.
Steps to design:
1) Take Parent Relative layout and make it centre vertical and horizontal
2) Place text1 and make align top of parent and give margin or padding from left
3) Place text2 below of text1 and give padding or margin from top.
4) Place text3 toRight of text1 or text2 or make make it centre vertical and horizontal of parent or you give margin left. it is your choice which once you choose.
Let me if you want more help. :)GlbMP
I have a layout contain one image and 3 text field
I've tried to align the image to right and text field to left but I've failed
I've used
android:layout_gravity="right" for image and left to text but it did not work also I've used end and start in gravity with no success
this is the layout code:
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:orientation="vertical"
android:background="#drawable/card_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/listthumb"
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:contentDescription="Rss video thumbnail"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/listtitle"
style="#style/listTitle"
android:maxLines="3"/>
</LinearLayout>
<TextView
android:id="#+id/shortdescription"
android:layout_width="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/listpubdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="11dp"/>
</LinearLayout>
</FrameLayout>
Try to use a <RelativeLayout> instead of a <LinearLayout>
With the RelativeLayout you could place a widget depending on the position of another widget
Here the Relative Layout description
Hope this will help, I have not had time to test....
One linear layout should have vertical orientation and contain the 3 text fields.
One linear layout should have horizontal orientation and contain both the above linear layout and the image.
To push two views to the edges of the screen, you can also give each a left/right margin and then put a blank view with weight = 1 in between them.
Please read a bit more on how layouts work on Android and the different types available to you. A LinearLayout will stack the containing Views either Horizontally or Vertically one after the other. A FrameLayout is simply a container and the items within have to position themselves. RelativeLayout allow you to position your views with a relative reference to other views (in your case, you can position your ImageView, and then your 3 TextViews relative to where the ImageView is).
If you can use LinearLayout instead of RelativeLayout, you should do so, as RelativeLayout is always slower, due to having to perform two passes prior to rendering as it needs to measure each view and then also perform the layouts based on that. You might be looking for something like (pseudo-code):
<LinearLayout orientation=horizontal>
<LinearLayout orientation=vertical>
<TextView />
<TextView />
<TextView />
</LinearLayout>
<ImageView />
</LinearLayout>
You have not described your question well . Check below code if it works .
You just forgot to add orientation in linear layout containing one text view and a Image view .
Add Orientation to Your Linear Layout.
I'm trying to place a TextView at the bottom of every activity by using the include... My code is below... I don't know why, but it remains at top... Although it works fine for TextView.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#E0E0E0"
android:orientation="vertical" />
<include
android:layout_alignParentBottom="true"
android:id="#+id/footer"
layout="#layout/footer" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:text="Hello"
android:textColor="#000000"
android:textSize="15dp" />
¿Maybe you are using a LinearLayout instead of a RelativeLayout? The latter doesn't have android:orientation property. We don't see the parent XML node, so just a guess
Also, you'll need to place the include at the bottom and the TextView above it
<TextView
...
android:layout_above="#id/footer" />
Right now you are overlapping both views
Another suggestion is to use FragmentActivity and a Fragment to handle the Footer, but that's out of the scope of this question.
Use RelativeLayout in your same xml code as the parent layout.
Well i got the solution.... I had to add the include inside another child relative layout...This is what i did..
enter code here
RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include
android:id="#+id/footer"
android:layout_alignParentBottom="true"
layout="#layout/footer" />
</RelativeLayout>
but...for a textview it works directly without using another child layout...So why do you need to do this for an include.....????:|
I checked your code. It works fine as posted in 1st post.
Please note that when you use layout tag then Eclipse' Graphical Layout won't draw the child xml-layout you've included (in your case footer.xml).
At the same time, you'll get a footer like you want if you run same code on actual device or emulator.
NOTE: you might want to remove android:layout_alignParentBottom="true" from textView1 as currently textView1 and footer layouts overlaps.
An app I am working on needs to have two buttons anchored to the bottom of the screen. The technique I've used in the past is to declare a RelativeLayout for the buttons within a parent RelativeLayout (height = fill_parent) and set align_parent_bottom to true. This is declared first and has an id so the next child layout can declare itself to be above the buttons' RelativeLayout.
However, the screen I'm currently working on has a strange problem - there is a large empty gap before the first View object appears:
Here is my layout XML
Can anyone spot where my problem is? Is there a better way to arrange my buttons?
Try this Code , It will work .
Problem is android:layout_above="#id/alarm_details_buttons_layout"
in Scroll View
Edited Code
I checked your code and here is the modification in your buttons layout:
<RelativeLayout
android:id="#+id/alarm_details_buttons_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<Button
android:id="#+id/alarm_details_return_to_list_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="your text here"
android:textSize="15sp" />
<Button
android:id="#+id/alarm_details_update_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/alarm_details_return_to_list_button"
android:state_enabled="false"
android:text="your text here"
android:textSize="15sp" />
</RelativeLayout>
fixed. http://pastebin.com/ucHwzJQP
Note i removed all "#string/", will need to be added back.
I solved the 'gap' problem. As I have set the scroll view to be positioned above the buttons RelativeLayout, I also had to force it to align with it's parent's top:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#id/alarm_details_buttons_layout"
android:orientation="vertical" >
I am designing this layout in my android xml file
I am putting 2 linear layout 1 for the header and other for the body. so far all good. In the header liner layout i added the background image which comes perfectly fine.
Now when i am adding the right most image button for search and information, i want them to float through the header linear layout exactly as shown above. But the problem is if i put them into header linerlayout the width of the liner layout increases and both of them comes under the header layout. Is there anyway i can achieve this?
Thanks
try this combination:
<AbsoluteLayout
android:id="#+id/widget68"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="40px"
android:layout_y="35px"
>
<ImageView
android:src = "#drawable/androidlogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:layout_width="124px"
android:layout_height="wrap_content"
android:text="Print Picture"
/>
</FrameLayout>
</AbsoluteLayout>
to get this:
You may also move your picture (button in this case) by padding it