Android Layout Issue - android

Hi I'm having a daft problem with my android application.
Currently it looks like this:
Is there a way of making the button go to the bottom in the middle? I've tried messing around but same effect. Also tried changing the fill_parent/wrap_content, relative/linear layouts and gravities.
This is the screenshot of the .xml file
many thanks.

There are a couple things you can do to get this, with the relative layout you're using this would work. Add these lines to your button section
android:layout_below="#+id/android:empty"
android:layout_alignParentBottom="true"
android:layout_alignParentCenter="true"

Add these two attributes to your Button
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
and these one to your textview:
android:layout_above="#id/insertion"
android:layout_height="fill_parent"
Read the API reference here:
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

May be you want to use a linear layout instead of the relative one...
With the LinearLayout you can place your item without thinking on their relative position.
You can place a vertical linear layout and inside it another layout for the list of reminders.
<LinearLayout android:orientation="vertical">
<ListView android:width="fill_parent"android:weight="2" />
<Button android:width="wrap_content" android:weight="1" />
</LinearLayout>
With weight option, you can choose to make the Button to be painted before the ListView.
EDIT: Reading other answers, I'm considering if you really need a RelativeLayout to place a button under a listview. I think you should learn how to handle simple view before to start using something more complex. If LinearLayout solve your problem, why don't use it? This is a personal observation...

Related

Android Shape containing multiple elements

How would one go about drawing a shape, then adding multiple elements to it?
At first I thought I should make use of either a textview, or a button, then simply apply a rectangle as a background. The problem with that is my text is all the same size.
I would also like to eventually add an image to the below purple button.
My end result should look like this:
What would be very nice, is if there was some sort of container that one could use... unfortunately I am new to android, so I do not know what to search for.
Just use a LinearLayout and put two TextViews in it:
<LinearLayout
android:orientation="vertical"
android:height="wrap_content"
android:width="wrap_content"
android:padding="20dp">
<TextView
android:text="123,150"
android:width="wrap_content"
android:height="wrap_content" />
<TextView
android:text="TOTAL PAGE VIEWS"
android:width="wrap_content"
android:height="wrap_content" />
</LinearLayout>
This is an untested example to give you something to start with, you'll have to adjust font size/color and background yourself.
you should look for a layout combinaison :
FrameLayout to have layout superposition
RelativeLayout to position items

Trying to put several textviews in a Button

I think I might be doing something stupid but I cannot find the answer. Obviously ht ebelow thing doesn't work but how would I do it?
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+#id/date"
android:text="+#id/heading"
android:text="+#id/subheading"
android:drawableLeft="+#id/featuredimage"
/>
I'm basically making an articlebutton to represent an article for a blog. I tried putting textviews inside but it miscounted the ending tags and threw an error.
What is that best way to create one of these buttons?
Dont use Button.
Use a Linear/Relative layout, with the attribute:
android:clickable="true"
Inside this layout add all your TextViews or any other thing you want.

Android Eclipse placing a text view in specific places

I'm creating this in a XML file and want a text view to be placed in a specific spot.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="200dp"
android:text="Text"
android:textColor="#color/blue"
/>
It's underneath the last button that was placed so it's around in the middle of the screen. I want it to be at the bottom of the screen of to the right.
Easy if you're using a RelativeLayout as parent.
android:layout_alignParentRight
android:layout_alignParentBottom
(check the capitalization, I'm not anywhere I can double check).
Using a RelativeLayout would be perfect if you would be specifying each views' positions. It is the most flexible layout among the Android Layouts.
Take a look at this tutorial. It discussed how to position views in a RelativeLayout.
I hope you can get ideas from it in solving your problem.

How can I get an image button's dimensions to make sense in android?

First of all, can I just say, I find laying out android UI's to be a frustrating experience? I used to think the XML layouts were simple and clean and awesome but every time I try to make anything with it I spend hours trying to do the simplest things!
In this particular instance I'm trying to make a simple horizontal bar that contains an image button of fixed size on the right and to the left of it I want an ImageView that takes up the rest of the available width. I see similar constructs all the time in the UI: the search box that appears at the top of the screen when searching, the text area and send button for composing text/googletalk messages, etc.
I've tried both a horizontal linear layout and a relative layout, and I can't get the button to look right in either one. My latest attempt has the following layout code:
It looks like this:
Using the hiearchyviewer indicates that both the imageview and the button have the same height (45px). And it shows the view dimensions and positions to be exactly what I'm looking for. Same height (differing widths of course since the ImageView is much wider). And they butt right up next to each other, centered in the Relative Layout. However the button as drawn on screen is obviously not taking up the full ImageButton view. I'm thinking it's something weird about the android system 9patch drawable used for the ImageButton background. But what do I know? I can't get it to look right no matter what I try.
How did you set up your RelativeLayout? Try to set it up like this:
<?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">
<ImageButton android:layout_width="wrap_content" android:src="#drawable/icon" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:id="#+id/imgButton"></ImageButton>
<ImageView android:id="#+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:src="#drawable/red_button" android:scaleType="fitXY" android:layout_alignBottom="#+id/imgButton" android:layout_alignTop="#+id/imgButton" android:layout_toLeftOf="#+id/imgButton"></ImageView>
</RelativeLayout>
Hope this helps.
If dimensions are exactly how you are looking for , then in ImageButton and ImageView , use android:scaleType="fitXY" and check.
For simple case , I might use linearlayout with horizontal orientation with two buttons in it with proper weights.

How to align views/widgets using only java, and no XML

I am developing an android app, where the entire UI is being developed in Java, since there's alot of dynamic stuff involved, like i might have to add buttons and checkboxes, depending on the user interaction.
I want to know how to position 2 different views relative to one another?
if i was using XML, i would've written like this:
<RelativeLayout ...
<EditText android:id="#+id/text1" .... />
<Button android:id="#+id/button1"
android:layout_toRightOf="#id/text1" .... />
</RelativeLayout>
Now how do i do the same thing using Java?
This is similar: How to lay out Views in RelativeLayout programmatically?
And this looks exactly like your question: Setting parameters on child views of a RelativeLayout

Categories

Resources