How to add heading to a Linear Layout - android

I have to create A GUI like below. I have used LinearLayout and created the border around it.I have to insert the header text between the border. Any idea how to do this.

<RelativeLayout>)
<LinearLayout with border>
<TextView with white background>
</RelativeLayout>
The TextView should appear above the linearlayout covering the border with his white background. You could position it using margins.

use relative layout as parent and put all your linearlayout code under relative layout. Then add textview in relative layout and mention that textview is on top and give marign.
<RelativeLayout>
<TextView android:layout_alignParentTop="true"
android:layout_margin="20dip/>
<LinearLayout>
// here is your linear layout
</LinearLayout>
</RelativeLayout>

Use RelativeLayout to overlap the line, you can't do that on Linearlayout

Related

How to align a layout to left while both left and right constraints are applied to it inside Constraint Layout?

This is the layout I want to design:
As you can see from the image, I want the linear layout to be constrained to both Item A and Item B and I want it aligned to left. I couldn't find any way to implement this inside a Constraint Layout. When I use this:
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="wrap_content"
android:layout_height="#dimen/ui_size_xs">
linear layout moves to the middle.
When I use this:
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="0dp"
android:layout_height="#dimen/ui_size_xs">
the linear layout occupies the whole area between Items A and B.
I want the linear layout to be wrap-content but should also align to the left like in the image. The only solution I could find is to create a new layout as parent of this linear layout and give 0dp to new parent linear layout and wrap-conent to this layout child layout. I don't want to do that. Is there any way to achieve this without creating any extra layout?
As mentioned in offical docs,
The default when encountering such opposite constraints is to center the widget; but you can tweak the positioning to favor one side over another using the bias attributes:
layout_constraintHorizontal_bias
layout_constraintVertical_bias
Try the following and see if it works
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="wrap_content"
android:layout_height="#dimen/ui_size_xs"
app:layout_constraintHorizontal_bias="0.3"
app:layout_constraintLeft_toRightOf="item1id"
app:layout_constraintRight_toLeft="item2id">
// try different horizontal bias values to meet your need

Most fitting View/Layout for placing several text- and image views inside, XML for Android

So I have this ScrollView inside which I have a RelativeLayout on one of my views on my Android app. Inside the RelativeLayout I already have a TableLayout that I'm using, and above it I want; 2 different text views (one header and one longer text, and I want the header to be placed on top of the longer bit of text) aswell as an ImageView that I want to be placed to the right of the 2 TextViews, and I want all 3 views to be placed on a differently colored background than the other stuff on the ScrollView such as the TableLayout for example.
I tried putting another RelativeLayout inside the ScrollView but it tells me ScrollView can only host one direct child, so that didn't really pan out. What would the most fitting way to accomplish this? Because I want this 3-view-background-thingie to scroll with the TableLayout and all the other stuff on the view.
As always, thankful for any answers or tips!
(My design kinda looks like this at the moment, schematically;)
<Container (that doesn't scroll)/>
<ScrollView
<RelativeLayout
*Alot of stuff here, such as a TableLayout for example
</RelativeLayout>
</ScrollView>
Put everything in your RelativeLayout
<ScrollView
<RelativeLayout
<LinearLayout>
<TextView>
</TextView>
<TextView>
</TextView>
<ImageView>
</ImageView>
</LinearLayout>
<TableLayout>
</TableLayout>
</RelativeLayout>
</ScrollView>
This way, the only child is the RelativeLayout, the others being children of the RelativeLayout.
Hope this helps!

Dynamically add imageViews in a circular layout in Android

I want to add imageViews dynamically in a circle like a round plate.
Android dose not provide a circular layout so please help me to create a circular layout..
Thanks in advance!
Just check this out , this link shows how to make view in circular shape... just imlement your image view in it ...
http://developer.samsung.com/android/samples-4
or you can do this by xml :
<LinearLayout orientation=vertical for whole screen>
<LinearLayout weight=1 gravity=center> <!--- Top --->
</LinearLayout>
<LinearLayout weight=1 orientation=horizontal> <!-- middle -->
<LinearLayout weight=1 gravity=left/>
<LinearLayout weight=1 gravity=right/>
</LinearLayout>
<LinearLayout weight=1> <!-- botton -->
<LinearLayout weight=1 gravity=center/>
<LinearLayout weight=1 gravity=center/>
</LinearLayout>
</LinearLayout>
You don't need a special layout for this.You can use a Relative Layout or a Frame Layout.
Just add the views dynamically in the normal way but position them using margin, padding etc so that they look like a circle.
From your question I can see that you need a circular layout on Android to arrange your images. I think this library will help you doing this. this library gives you the ability to add item, rotate them with animation. Check it out!
You can use HorizontalScrollView.

Add a Textview to a FrameLayout in a determined position

I'm trying to add a textView to a frameLayout. The TextView has wrap_content properties, so it grows when the text grows. I'm adding it to a FrameLayout with this function:
((FrameLayout) findViewById(R.id.mainLayout)).addView(mEditText);
This is the xml of the frame layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</FrameLayout>
The textView always appears in the top left corner of the screen. I'd like to position it in the middle, or top middle. How can this be done?
I looked over the answers in How can I dynamically set the position of view in Android? and they weren't much help :( Mainly caused crashes..
Try this:
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
((FrameLayout) findViewById(R.id.mainLayout)).addView(mEditText, params);
Change Gravity to suit your need.
BTW, the frame layout should use fill_parent for width and height
Try to gravity or Layout gravity to your Framelayout or the Textview. It makes your Layout to the center of the screen. Use like this,
android:layout_gravity="center"
or
android:gravity="center"
Add android:layout_gravity="center" in your frame layout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
</FrameLayout>
you can try it by set the gravity of text use it like-
textview.setGravity(Gravity.center);
othervise by xml set gravity to center so it will display you in center and if you'll use centerinparents so it will always apperas at the center of screen.
Set FrameLayout properties android:layout_width and android:layout_height to fill_parent and also set TextView property LayoutGravity . such as Center, Right or Top.
Thanks
Setting the gravity programatically definitely works
Please set the layout_gravity to right in the xml
TextView.setGravity(Gravity.RIGHT);

Android overlay outside/between layout boundaries

I have to add an overlay (ImageView) so that it's a bit shifted to the left of the containing layout's left boundary.
What is the best way to do this?
Tried something simple, like putting the ImageView inside the layout and use negative margin
android:layout_marginLeft="-20dip"
This made this:
(Correction: Text in the image should be 20dip not 20px)
AbsoluteLayout is deprecated. Is there something like z-order? Or what do I do?
Thanks in advance.
Edit: I tried using relative layout instead. Same effect. Here's the xml reduced to a minimum:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:paddingLeft="50dip"
>
<ImageView
android:id="#+id/myId"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_marginLeft="-30dip"
android:clipChildren="false"
android:src="#drawable/pic" />
</RelativeLayout>
Result
Also happens when the containing layout has a background image smaller than the screen instead of padding.
Using RelativeLayout instead of LinearLayout (to allow overlapping) and adding this to the RelativeLayout fixed it:
android:clipToPadding="false"
set "android:clipChildren = false" in xml
Instead of
android:layout_marginLeft="-30dip"
try with
android:paddingLeft="-30dp"
Use a transparent(android:background="#00000000") imageview to the left of linear layout with width = 30dp. And make myId as aligning left in case of relative layout. If you are using linear layout make orientation as horizontal and let the transparent imageview be the first entry in it.

Categories

Resources