【问题标题】:how to write a text view on the image view? [duplicate]如何在图像视图上编写文本视图? [复制]
【发布时间】:2013-09-17 11:45:52
【问题描述】:

我想在图像视图顶部实现一个文本视图,用户可以在其中定义自己类型的文本,并可以在图像视图顶部保存文本。谁能帮助我提供好的教程? 这是我的 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]);
  }

}

【问题讨论】:

    标签: android android-layout android-listview android-emulator


    【解决方案1】:
    < 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 >
    

    【讨论】:

      【解决方案2】:

      你需要使用 customviews.. 使用画布在图像上写入文本覆盖 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 ( ) ;
          }
      
      }
      

      【讨论】:

        【解决方案3】:

        在你的布局中添加这个

        <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中

        【讨论】:

        • +1 我正在寻找 :)
        【解决方案4】:

        将你的两个观点放在一个FrameLayoutRelativeLayout 中怎么样?

        Android 团队的 Romain Guy 提出了一个出色的 tutorialFrameLayout 来实现这一结果。

        然后,当用户点击前者时,您可以用EditText 替换(隐藏/显示)您的TextView。或者您甚至可以显示dialog 以允许用户更改文本。

        【讨论】:

          【解决方案5】:

          我使用相对布局来覆盖视图。尝试使用相对布局

          <?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>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-12-15
            • 2012-08-29
            相关资源
            最近更新 更多