In my layout, I really need to the TableView be the root view, but inside it I need very much a single TextView to be aligned to the right border of the screen, but I keep receiving the warning: Invalid layout param in a TableLayout: layout_alignParentRight activity_main.xml
What should I do to have a aligned textview inside a TableView?
You can use gravity in TableLayout, Try to set android:gravity="right" to TextView
android:layout_alignParentRight="true" works fine for me if it's not working then check your parent try fill_parent on the parent or try moving it from it's parent layout hope this helps
Related
Let's say I have two views that I want to center vertically. The first view is bigger than the second view.
I noticed that if I place theses two views inside a RelativeLayout with properties layout_height="wrap_content" and android:gravity="center_vertical" nothing happens. This is what I get :
In the opposite, if I place these two views inside a LinearLayour with properties layout_height="wrap_content" and android:gravity="center_vertical" the views are centered vertically :
Lastly, if I place these two views inside a RelativeLayout with properties layout_height with a fixed height and android:gravity="center_vertical" I get the same result as the LinearLayout. The views are centered vertically.
I would expect the views to be centered vertically in each case. Do you know the reason for this difference?
LinearLayout handles all its child object based on its orientation (Horizontal or vertical). So when you are saying gravity: "center_vertical". You are actually referencing based on your parent layout.
In case of RelativeLayout,it enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent).
Personally I would use gravity only in LinearLayouts and the centerInParent for RelativeLayouts.
In your first case it'll work with RelativeLayout as you expected if you use android:layout_centerVertical="true" to the child view which you want to be centred.
So in case of LinearLayout you need to specify the orientation first (i.e. horizontal/vertical) so that the child views are inflated based on the reference of your parent layout.
While in RelativeLayout, as the name says it all, you can specify the position with respect to the views which are the child of a parent RelativeLayout.
Now the views you want to achieve can be generated in many other ways too.
For example, set your parent layout as LinearLayout. Don't specify any gravity attribute in the parent layout. Hence, you set a layout_gravity attribute to the child to certer_vertical and this should work too.
Well, after some others tests, it seems that the behavior of android:gravity for a RelativeLayout is a bit random. I will just avoid to use is.
I have the android xml layout using DroidDraw :
link : https://docs.google.com/document/d/1L3QJVwI9Znmeu1yANJXhDcZGFR70587d4oznu0hrZCw/edit?usp=sharing0
I need to bottom align the last Textview (Yellow one as indicated in the print screen).
i.e.
I need this :
Try using
android:alignParentBottom="true"
If I see correctly that the parent ViewGroup of your TextView is a RelativeLayout
Set the parent relative layout property to:
android:layout_gravity = "bottom | left"
In Relative layout use:
android:alignParentBottom="true"
and In Linear layout use:
android:layout_weight="1.0"
android:gravity="bottom|right"
This post did the trick.
stackOverflow link
I needed to implement layout_weight on my layouts. Basically defining weights for header, content and footer
how can i mange Textview in layout.? please help me..
how can i set textview and border then again textview.
Just create a horizontal LinearLayout, and add an ImageView, a TextView, a View with width 2dp and height match_parent, and a TextView as children.
Either repeat that for every row, or use the recommended approach of using a ListView with the above mentioned layout as rows.
I'd use two compound TextViews: Just create a horizontal LinearLayout, and add a TextView with drawableLeft="#drawable/icon_location" and another one with drawableLeft="#drawable/line_vertical" as children.
For both, a drawablePadding="8dp" or whatever you like best
I have done some basic xml layout from the Internet and I am confused as to what android:gravity would be used for vs android:layout-gravity. The UI designer seems to respond well when I change the layout_gravity, but I get no response to the regular gravity? What is up with this?
Is this similar to layout parameters with fill-parent and match-parent? one is gone now.
android:gravity is a statement from a parent to its content, indicating where the content should slide within the available parent space (if there is room for such sliding).
android:layout_gravity is a request from a child to its parent, asking that it be slid in a certain direction (if there is room for such sliding).
layout_gravity - It contains and it belongs to component's parent layout. Like if you set one TextView in LinearLayout, LinearLayout's width is fill_parent, but TextView basically will set at left-top. So now if you would give layout_gravity=right then your TextView will be shifted to top-right corner. But the text will not change its place. i.e. you had been wrote "Hello world" then "hello world" will not be changed to right, but its parent textView will be changed to right. So here in this case it will belongs to LinearLayout, means parent Layout.
gravity- It contains and it belongs to TextView as per above explanation. if you will give gravity="right" then "Hello-world" text will go to right-top corner of TextView not LinearLayout.
I have this layout:
It was a bit tricky to put ListView inside ScrollView, but it worked.
When the list is large and the scroll appears when scrolling .. everything up, including the form. That is ok!
Now I would like to put a TextView fixed at the bottom of the screen. As a total
Tried to wrap everything with a RelativeLayout put layout_weight = "1" in ScrollView. Worked. But when the keyboard appears, rises along the TextView and do not want it.
How do I set a TextView at the bottom of the screen, without moving when the keyboard appears?
Put everything in a relative layout. Add the TextView to the relative layout, set layout_alignParentBottom on TextView. Then on the ScrollView set layout_above referencing the TextView.
Follow the design hierarchy:
<LinearLayout.....>
<ScrollView>
<You Old Views/>
</ScrollView
<TextView> .. </TextView>
</LinearLayout>