Android LinearLayout / TableLayout with custom ListAdapter. Making List items of book previews
I have used RelativeLayout for a custom implementation of a ListAdapter and I am not sure if I can continue using this or if I need to use TableLayout.
In the first example I have the text positioned as I would like by using one image view and one text view containing the book name and the author name. However, I want to style the author text differently so I think I will need two text views.
In the second example I have added another text view but it floats to the right. Second eg is Clipboard02.png.
How can I make the second text view go under the first text (as in eg 1). I have done this in code rather than using XML layout.
http://carriehall.co.uk/Clipboard01.png
LinearLayout.LayoutParams skyParams = new LinearLayout.LayoutPar开发者_StackOverflow中文版ams( 70,
LayoutParams.WRAP_CONTENT );
ImageView skyControl = new ImageView( context );
skyControl.setImageResource( R.drawable.the_eyre_affair );
addView( skyControl, skyParams );
LinearLayout.LayoutParams bookParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
bookParams.setMargins( 5, 10, 5, 10 );
TextView bookControl = new TextView( context );
bookControl.setTextAppearance( context, R.style.SpecialText );
bookControl.setText( book.getTitle( ) + "\n\n" + book.getAuthor( ));
addView( bookControl, bookParams );
Slightly clumsy work around:
LinearLayout ll = new LinearLayout(getApplicationContext());
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
ll.setOrientation(LinearLayout.VERTICAL);
TextView author = new TextView(getApplicationContext());
TextView book = new TextView(getApplicationContext());
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ll.addView(author, params);
ll.addView(book, params);
If you are only looking at simple font change (Bold/Italics/Underline) you can use HTML formatting (eg.< b/> etc) in the same text view. You can further optimize the layout by setting the image using author.setCompoundDrawablesWithIntrinsicBounds(BookCoverDrawable, null, null, null);
精彩评论