我想在图像视图的顶部实现一个文本视图,用户可以在其中定义自己类型的文本,并可以在图像视图的顶部保存文本。任何人都可以帮助我提供良好的教程吗? 这是我的Fullimage活动课
public class FullImageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullimage);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.fullimage);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
}
}
答案 0 :(得分:2)
< Relativelayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
< ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/contact" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/image" />
</Relativelayout >
答案 1 :(得分:1)
您需要使用自定义视图。使用画布在图像覆盖onDraw()方法
上写入文本 @ Override
public void onDraw ( Canvas canvas ) {
try {
canvas.drawColor ( Color.BLACK ) ;
bitmap = BitmapFactory.decodeResource ( getResources ( ) , ( R.drawable.background_image ) ) ;
canvas.drawBitmap ( bitmap , 0 , 0 , null ) ;
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawText("Text to be drwaw", my_txt_x_position, my_txt_y_position, paint);
} catch ( Exception e ) {
e.printStackTrace ( ) ;
} catch ( Error e ) {
e.printStackTrace ( ) ;
}
}
答案 2 :(得分:1)
在你的布局中添加
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/contact" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/image"
android:background="#77000000"
android:paddingBottom="14dip"
android:paddingLeft="8dip"
android:paddingTop="14dip"
android:text="Load and user your OWN photos!"
android:textColor="#FFFFFFFF"
android:textSize="18sp" />
确保它应该在标签RelativeLayout
中答案 3 :(得分:0)
我使用相对布局覆盖视图。尝试使用相对布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/img_corct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bt" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/img_corct"
android:layout_alignLeft="@+id/img_corct"
android:layout_alignRight="@+id/img_corct"
android:layout_alignTop="@+id/img_corct"
android:text="Sample Text"
android:textColor="#000000"
android:textSize="24sp" />
</RelativeLayout>
答案 4 :(得分:0)
答案 5 :(得分:0)