Trying to put several textviews in a Button - android

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.

Related

What is the small graphic displayed under an EditText called and how can I remove it?

After some pretty thorough googling I still cannot figure out what the the little graphic that's displayed under the text in and EditText View is called. I would also like to remove it either using XML or programmatically. The little graphic is the thing under the cursor in this image: http://1.bp.blogspot.com/-UAuOq0h4Vok/T8reinvaWPI/AAAAAAAABPc/N4yibXd3kZg/s1600/android%2Bedittext%2Btext%2Bchange%2Blistener%2Bexample.jpg . Sorry if this is a dumb question, but without the name of this little graphic feature I can't seem to find out anything about it.
It is the background drawable associated with the edittext. You can change it by manually setting the background to something yourself, such as
<EditText
android:background="#android:color/transparent"
...
/>
Try this..
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hello"
android:background="#00000000"
/>
if you want transparancy just put 80 before the actual hash code.
#80000000
This will change any colour you want to transparent one.. :)
you probably have in your layout
android:minLines="2"
try to remove it

How to make a sectionised ListView

I have been searching all day on how to make these sections in a ListView. Haven't found anything yet. I have been through many blogs and most of them talk about the approach CommonsWare takes (i.e. SectionAdapter) but the SectionAdapter.java is nowhere to be seen on his GitHub repo.
How can this be made? (i.e. the part marked A. I am not trying to make a Preferences list. Something more on the lines of a Contact List)
I struggled a lot on this. There are a number of ways to do this. The one I found simplest and which I recommend is using separator view in your list item layout (the one you inflate in get view) and change its visibility based on whether on not there should be a header. I use something like this:
<TextView
android:id="#+id/separator"
android:layout_width="fill_parent"
android:visibility="gone"
android:layout_height="wrap_content" />
I found this much simpler than the other adapter. I just kept track of where I wanted to have a separator using a variable and based on that I setVisibility(View.VISIBLE) in my getView().
Try putting this on the textview in the xml:
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:id="#+id/tv_separator"
android:visibility="gone"
/>
this will make it like preferences categories that looks much better..

Android Layout Elements

I'm trying to make an Android layout like the one below. I have a couple of questions:
1 - what is the element called that FB uses for posts? Ie, it doesn't look like a text view, but the element looks like it separates each post with a divider line. Also, the text style is different for a person's name and how long ago they posted. I'm looking to duplicate this (minus pictures) but I can't find the right UI elements.
What is the element called at the bottom? It's like a static menu. IE, it's the same as a menu but instead of pressing "menu" to access it, it's on the page at all times.
Finally, are there good tutorials/examples on how to make nice looking, professional layouts like the apps on the market? The tutorials that I've found on layouts are really basic. I'd like to understand what elements exist, what all of the attributes mean and see examples, etc. So far I'm only able to see the capabilities from other applications. I'd like to have a handbook or some type of some type of reference manual to go to.
For the "fancy" text views you can make a linear layout that hosts a <RelativeLayout>:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0">
<ImageView
android:id="#+id/userPhoto"
android:layout_height="64dip"
android:layout_width="64dip"
/>
<TextView
android:id="#+id/userFullName"
android:layout_height="25dp"
android:layout_width="fill_parent"
android:layout_marginLeft="70dp"
/>
</RelativeLayout>
Once you have a relative layout you can add different views inside of that to create a sort of customeized view.
As far as good examples I would look at this book. It's easy to understand and very helpful on such things.
I found a really helpful tutorial to solve a problem in ListView Row design a bit like yours. It goes a bit further explaining how to do Async Image loading but the first part should help you.
Also, I might be wrong (I am still a bit new to this) but I think the answer above lacks a TextView for the actual message besides the userName and the relative positions of the elements since it is a relative layout. Something like:
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/userPhoto"
android:layout_toRightOf="#id/userPhoto"
android:textSize="17dp"
android:textStyle="bold" />
<!-- actual message -->
<TextView
android:id="#+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/userName"
android:layout_marginTop="1dip"
android:layout_toRightOf="#id/userPhoto"
android:textSize="15dp" />
The key in organizing a relative layout is:
android:layout_alignTop="#id/userPhoto"
android:layout_toRightOf="#id/userPhoto"
and
android:layout_below="#id/userName"
android:layout_toRightOf="#id/userPhoto"
I might be wrong but if it helps, great! Just adding my bit to the other answer.
Cheers

Android Layout Issue

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...

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