listview
, das ein einzelnes imageview
hat, das Vertikal scrollbar isttextview
auf Imageview
zu platzieren.list_view_item_for_images.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:tools="http://schemas.Android.com/tools"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent" >
<ImageView
Android:id="@+id/flag"
Android:layout_width="fill_parent"
Android:layout_height="250dp"
Android:layout_alignParentLeft="true"
Android:layout_alignParentRight="true"
Android:scaleType="fitXY"
Android:src="@drawable/ic_launcher" />
</RelativeLayout>
Es gibt eine Ausgabe wie unten
Wie mache ich so etwas wie unten
note :: Dish 1 & 2 sind Textansichten
Dies sollte Ihnen das erforderliche Layout geben:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:tools="http://schemas.Android.com/tools"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent" >
<ImageView
Android:id="@+id/flag"
Android:layout_width="fill_parent"
Android:layout_height="250dp"
Android:layout_alignParentLeft="true"
Android:layout_alignParentRight="true"
Android:scaleType="fitXY"
Android:src="@drawable/ic_launcher" />
<TextView
Android:id="@+id/textview"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_alignParentTop="true"
Android:layout_marginTop="20dp"
Android:layout_centerHorizontal="true" />
</RelativeLayout>
Spielen Sie mit dem Android:layout_marginTop="20dp"
, um zu sehen, welcher besser zu Ihnen passt. Verwenden Sie die ID textview
, um den Android:text
-Wert dynamisch festzulegen.
Da ein RelativeLayout seine untergeordneten Elemente stapelt, wird beim Definieren der TextView nach ImageView die ImageView 'über' gesetzt.
HINWEIS: Ähnliche Ergebnisse können mit einer FrameLayout
als übergeordnetem Element zusammen mit der Effizienzsteigerung gegenüber anderen Android-Containern erzielt werden. Vielen Dank an Igor Ganapolsky
(siehe Kommentar unten) für den Hinweis, dass diese Antwort aktualisiert werden muss.
Versuche dies:
<RelativeLayout
xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:id="@+id/rel_layout"
Android:layout_width="match_parent"
Android:layout_height="match_parent" >
<ImageView
Android:id="@+id/ImageView"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:src=//source of image />
<TextView
Android:id="@+id/ImageViewText"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_alignLeft="@id/ImageView"
Android:layout_alignTop="@id/ImageView"
Android:layout_alignRight="@id/ImageView"
Android:layout_alignBottom="@id/ImageView"
Android:text=//u r text here
Android:gravity="center"
/>
Hoffe das könnte dir helfen.
sie können framelayout verwenden, um dies zu erreichen.
wie ist Framelayout anzuwenden?
<FrameLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent">
<ImageView
Android:src="@drawable/ic_launcher"
Android:scaleType="fitCenter"
Android:layout_height="250px"
Android:layout_width="250px"/>
<TextView
Android:text="Frame Demo"
Android:textSize="30px"
Android:textStyle="bold"
Android:layout_height="fill_parent"
Android:layout_width="fill_parent"
Android:gravity="center"/>
</FrameLayout>
ref: tutorialspoint
sie können dies auch versuchen. Ich verwende nur Framelayout.
<FrameLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:background="@drawable/cover"
Android:gravity="bottom">
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:textAppearance="?android:attr/textAppearanceMedium"
Android:text="Hello !"
Android:id="@+id/welcomeTV"
Android:textColor="@color/textColor"
Android:layout_gravity="left|bottom" />
</FrameLayout>
ziehen Sie einfach die Textansicht in Eclipse über ImageView
<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:paddingBottom="@dimen/activity_vertical_margin"
Android:paddingLeft="@dimen/activity_horizontal_margin"
Android:paddingRight="@dimen/activity_horizontal_margin"
Android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
Android:id="@+id/imageView1"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_alignParentLeft="true"
Android:layout_alignParentTop="true"
Android:layout_marginLeft="48dp"
Android:layout_marginTop="114dp"
Android:src="@drawable/bluehills" />
<TextView
Android:id="@+id/textView1"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_alignLeft="@+id/imageView1"
Android:layout_centerVertical="true"
Android:layout_marginLeft="85dp"
Android:text="TextView" />
</RelativeLayout>
Und dies ist die Ausgabe der obigen XML
Wie Sie im OP erwähnt haben, müssen Sie Text
auf ImageView
programmgesteuert überlagern. Sie können ImageView
drawable erhalten und mit Hilfe von Canvas
und Paint
darauf schreiben.
private BitmapDrawable writeTextOnDrawable(int drawableId, String text)
{
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);
Paint paint = new Paint();
Paint.setStyle(Style.FILL);
Paint.setColor(Color.WHITE);
Paint.setTypeface(tf);
Paint.setTextAlign(Align.CENTER);
Paint.setTextSize(11);
Rect textRect = new Rect();
Paint.getTextBounds(text, 0, text.length(), textRect);
Canvas canvas = new Canvas(bm);
canvas.drawText(text, xPos, yPos, Paint);
return new BitmapDrawable(getResources(), bm);
}