<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" android:background="#drawable/robo">
<TextView android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Max Time(Sec)">
</TextView>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:id="#+id/maximum"
android:inputType="number">
</EditText>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="#+id/startbtn"
android:focusable="true">
</Button>
<ImageButton android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/icon"
android:id="#+id/imageButton1">
</ImageButton>
</LinearLayout>
In LinearLayout you can't change positions a whole lot - because the layout is Linear (sequential). But you can use layout_margin to somewhat move the widgets.
I don't know what you want to do, but you should look into FrameLayout (which will let you put the image anywhere!). My personal favorite is RelativeLayout.
Position depends on position of it's parent container/component (Layout) and on it's layout_* properties.
And u did'n tell what u want. If u want change it position - switch it with another view in Layout.
put more buttons in layout and hide or show them according to your needs
views in android are in relationship, not only in RelativeLayout but in Others, so you should choose the best way to describe your app layout, using more than one is commonly used.
to change position of label, you 'd better using AbsoluteLayout then using android:layout_x="", android:layout_y=""
what is your exact requirement???
you can put two buttons and make one visible and other one invisible or vice verse.or you can put layout_margin for all direction.And try to put all your component in different layout.
Related
May i ask how to put icon on my button like the image below?
And also where can i have resources or sample resources of buttons like this?
You'll need to set the drawable to the left of your Button. Either via xml or programmatically.
Either create a button and set a compound drawable or create an ImageButton.
<TextView android:id="#+id/login_with_facebook"
android:layout_width="100dp"
android:height="48dp"
android:text="FACEBOOK"
android:gravity="center"
android:drawableLeft="#drawable/facebook_icon_48_x_48"
android:clickable="true"/>
<Button android:drawableLeft="#drawable/image"
android:text="facebook"/>
If u want space between image and text, then give drawablePadding Like:
<Button android:drawableLeft="#drawable/image"
android:text="facebook"
android:drawablePadding="10dp"/>
using RelativeLayout it can be done easily. here I got snippet for you,
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/fb_logo_button"
android:text=""
android:background="fb_logo"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<Button
android:layout_toRightOf="#id/fb_logo_button"
android:id="#+id/fb_text_button"
android:text="Facebook"
android:textAlignment="center"
android:background="#android:color/holo_blue_bright"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</RelativeLayout>
this will ensure that whatever your images are for respective DPIs, it will align this layout to center horizontally. Within this layout logo will be always to left of text as in picture.
This is applicable when your parent is also a RelativeLayout. If you got LinearLayout as parent then in above RelativeLayout tag change android:layout_centerHorizontal="true" to android:layout_gravity="center_horizontal"
I can't test it in eclipse as I'm out of home. Try this and let me know. Thanks.
I've tried a couple of things and read many topics, but I didn't find any solution for my problem.
At the moment I have an xml file with the layout on the picture. This is how it should look like the design and I did it with LinearLayouts and works perfect.
The problem is that I want when I click somewhere on the screen to add a highlighted column from top to bottom.
I read that this should be done with RelativeLayout, but I tried to do it that way, but I can't arrange my other elements to be with equal size.
Do you know how this could be done ?
This is part of my xml:
<LinearLayout
android:id="#+id/chart1Layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:background="#color/color"
android:gravity="bottom|center"
android:maxLines="4"
android:padding="3dp"
android:text="#string/cap"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/orange"
android:textSize="30sp"
android:textStyle="bold" />
<com.some.chart
android:id="#+id/result_widget_chartView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="8"
palette="grayscale"
android:background="#color/dark_header"
android:padding="0dp"
android:paddingBottom="0dp"
android:paddingLeft="10dp" />
</LinearLayout>
Design : http://i.stack.imgur.com/fkHvG.png
Thanks a lot.
see my pic:
if this what you want?
Thanks for your answers. It's not exactly what I tried to achieve, but you gave some direction and I did it as I want.
The solutions was to add Relative Layout as root and keep everything as-is, to keep the design.
http://i.stack.imgur.com/j18Dw.png
I was doing wrong when I tried to replace my Linear layout container with Relative layout - I just needed to add all my things in new Relative container (not to replace).
Thanks.
How can i do 1 button with 2 labels with different style inside in android?
(Like the image)
Thank's
You can create a custom view. I have used Layout as a button by setting custom button style to the layout and have added two textViews to it, this way:
<LinearLayout android:id="#+id/customButtonLayout"
android:layout_height="wrap_content" style="#android:style/Widget.Button"
android:layout_width="wrap_content">
<TextView android:text="First" android:id="#+id/firstTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#000"></TextView>
<TextView android:textColor="#000" android:text="Second"
android:layout_height="wrap_content" android:id="#+id/secondTextView"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"></TextView>
</LinearLayout>
The only way I can think with which you could applay different textstyles to a Button is to use HTML (with HTML.fromHTML()). But I wouldn't recommend that, because probably it wouldn't look good. Use a Layout instead(Linear - or RealtivLayout). Add two TextViews to it and set a selector as the background(to have a "click-effect").
I'm a beginner in Android. I use Eclipse to program my app. When I create an .xml class and I want to set the specific position of a button, I use this code for example:
<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"
android:background="#drawable/fm"
android:baselineAligned="false"
android:gravity="end" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollX="100dp"
android:scrollY="30dp"
android:text="#string/edad" />
</RelativeLayout>
... but nothing happens. It sets the button in a corner. How can I get it to appear elsewhere?
you need to use
android:layout_marginRight
android:layout_marginLeft
android:layout_marginTop
android:layout_marginBottom
You need to use positioning parameters such as android:layout_below. See the Relative Layout Guide for details.
You should click the button and go property. That's where the diffrent positioning settings are located.
For example below :#+id/VIEW then set marin top : 10dip. This will set you button 10 dip below VIEW.
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="30dp"
android:text="#string/edad" />
I am trying to put the zoom controls of the map on the bottom right corner of screen. I could do it with RelativeLayout using both alignParentBottom="true" and alignParentRight="true", but with Framelayout I did not find any such attributes. How do I align it to the bottom-right of screen?
Actually it's possible, despite what's being said in other answers. If you have a FrameLayout, and want to position a child item to the bottom, you can use android:layout_gravity="bottom" and that is going to align that child to the bottom of the FrameLayout.
I know it works because I'm using it. I know is late, but it might come handy to others since this ranks in the top positions on google
I also ran into this situation and figured out how to do it using FrameLayout.
The following output is produced by the code given below.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/contactbook_icon"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="140"
android:textSize="12dp"
android:textColor="#FFFFFF"
android:layout_gravity="bottom|right"
android:layout_margin="15dp" />
</FrameLayout>
Change the margin value to adjust the text position over the image. Removing margin might make the text to go out of the view sometimes.
It can be achieved using RelativeLayout
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="#drawable/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Setting android:layout_gravity="bottom|right" worked for me
Two ways to do this:
1) Using a Frame Layout
android:layout_gravity="bottom|right"
2) Using a Relative Layout
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
If you want to try with java code. Here you go -
final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
yourView.setLayoutParams(params);
params.gravity = Gravity.BOTTOM; // set gravity
Use bottom|right as the layout_gravity value of the element which you wish to align in the bottom right position of the parent layout.
android:layout_gravity="bottom|right"
you can add an invisible TextView to the FrameLayout.
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="invisible"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<Button
android:id="#+id/daily_delete_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="DELETE"
android:layout_gravity="center"/>
<Button
android:id="#+id/daily_save_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="SAVE"
android:layout_gravity="center"/>
</LinearLayout>
There are many methods to do this using constraint widget of the activity.xml page of android studio.
Two most common methods are:
Select your button view and adjust it's margins.
Go to "All attributes",then to "layout_constraints",then select
layout_constraintBottom_toBottomOf_parent
layout_constraintRight_toRightOf_parent
You can't do it with FrameLayout.
From spec:
http://developer.android.com/reference/android/widget/FrameLayout.html
"FrameLayout is designed to block out an area on the screen to display a single item. You can add multiple children to a FrameLayout, but all children are pegged to the top left of the screen."
Why not to use RelativeLayout?