[android-developers] Displaying Image
Hello Folks,
I am a beginner in Android platform. I am reading the content and
displaying it. With this I want to display an image. Top image should
come and followed by the text. I am done with reading the content from
a file and displaying it and also the image. But the image is taking
the full screen, I want to display a small image and not as a
background image.
Here is my layout and class file.
SMSMessage.java
package com.example.message;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class SMSMessage extends Activity {
/** Called when the activity is first created. */
private ImageView imageView;
private LinearLayout sampleLayout;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = new TextView(this);
try {
InputStream is = this.getResources().openRawResource(
R.raw.my_base_data);
// i have kept my_base_data.txt in the raw folder
if (is.available() > 0) // check if file exist
{
// Read text from file
StringBuilder text = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
text.append(line);
text.append('\n');
}
tv1.setBackgroundResource(R.drawable.flora);
tv1.setText(text.toString());
//setContentView(imageView);
setContentView(tv1);
} else {
Toast.makeText(
this.getApplicationContext(),
"File not found. Please upload it!!!",
Toast.LENGTH_LONG).show();
}
}
catch (IOException e) {
// You'll need to add proper error handling here
}
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:id="@+id/samplelayout">
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Thought of the day"
android:paddingLeft="5dip"
android:textStyle="bold"/>
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView1"
android:layout_marginRight="20dp"
android:layout_gravity="right|center_vertical"
android:src="@drawable/flora"/>
</LinearLayout>
Please help to resolve this.
Image Text
In this format I am looking for
Thanks all
Ambika
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home