3

Possible Duplicate:
How can I implement a 'Lettrine' render in android?

In my applications i want to show news ( from databse ) in a view, for that i have to create this type of view shows in image below.

i want to set image in the image view, title in TextView one and Description in textView 2.. text length will be vary

it should be look like news page . like below image.

enter image description here

Community
  • 1
  • 1
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166

3 Answers3

2

It'll be better for you to use not the layout, but markup your news as HTML and put it into WebView.

Otherwise you can take look at the Spannable, add Image as ImageSpan to TextView and (afaik) you can modify the way how text aligns to image.

OleGG
  • 8,589
  • 1
  • 28
  • 34
  • those are not coming from web from DB.. – RajaReddy PolamReddy Feb 17 '12 at 05:45
  • You can use `Html.toHtml()` method to produce HTML from your text (strings, for example). – OleGG Feb 17 '12 at 06:04
  • 1
    +1 All layouts in Android assume the content is rectangular. The text will necessarly be over, or under or next to the image. It's not possible to create the lettrine effect the OP wants. – rds Feb 22 '12 at 16:42
0

ok, psuedo code:

<RelativeLayout>

<TextView id=TextView2 width/height=fill_parent />

<ImageView id=ImageView1 width/height=wrap_content 
       layout_alignparenttop=true layout_alignparent_left=true/>
<TextView id=TextView1 width/height=wrap_content 
       layout_alignparenttop=true layout_alignparentright=true />
</RelativeLayout>

The trick is to use a RelativeLayout as the parent, and then the layout_alignParentX set of attributes to define a relative location on screen. Also, the above psuedo-layout assumes TextView2 will go behind the image view.

edthethird
  • 6,263
  • 2
  • 24
  • 34
  • that will lay them out like that yes, but when he actually puts text on TextView2 he would need to know the cursor location so as to jump till after the image... – L7ColWinters Feb 17 '12 at 04:54
  • .setSelection(n), part of textView so that way you can specify where the cursor will go to – L7ColWinters Feb 17 '12 at 05:06
  • this is not the solution, i want to start description cursor after title text completed and after image text have to start from left end. – RajaReddy PolamReddy Feb 17 '12 at 05:11
0

check this out

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#ffffff"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="#0059A9"
    android:gravity="center"
    android:padding="50dip"
    android:text="TextView 1" />

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="10dip"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#0059A9"
        android:gravity="center"
        android:padding="50dip"
        android:text="TextView 1" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_gravity="left"

        android:background="#ffffff"
        android:contentDescription="Image View"
        android:src="@drawable/image_no" />
</RelativeLayout>

Akram
  • 7,548
  • 8
  • 45
  • 72
  • text view 2 getting margin depending on the image width. from top to bottom , what i want is text should come along with image height after image it shall come below of image view also... – RajaReddy PolamReddy Feb 17 '12 at 10:31