Java 图像视图上的文本视图?

Java 图像视图上的文本视图?,java,android,string,Java,Android,String,文本应保存在图像视图中?文本不应在布局文件夹中定义,而应保存在键盘上相应的图像视图中 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fullimage); // get intent data Intent i = getIn

文本应保存在图像视图中?文本不应在布局文件夹中定义,而应保存在键盘上相应的图像视图中

   @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]);
    }

}

请使用framelayout。。定义ImageView和TextView,并在TextView上设置文本

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/thumbHolder">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/thumbImage"
            android:scaleType="fitXY" />


        <TextView
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:id="@+id/titletxt"
            android:gravity="center_vertical"
            android:maxLines="2"
            android:paddingRight="8dp"
            android:paddingLeft="8dp"
            android:textSize="16sp"
            android:layout_gravity="bottom"
            android:background="#80000000"
            android:textColor="#ffffffff"
            android:text="" />


    </FrameLayout>

用于设置自定义字体:-

  • 创建“assets\fonsts\”文件夹,然后将字体放在那里
  • 然后通过加载该字体创建字体:-

    Typeface tfBold=Typeface.createFromAsset(getActivity().getAssets(),“fonts/Raleway Bold.otf”)

  • 然后在文本视图中设置字体:-

    yourTextView.setTypeface(tfBold)

  • 试试这个-

       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" 
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@drawable/image">
    
    
            <LinearLayout 
                android:layout_height="fill_parent"
                android:layout_width="fill_parent" 
                android:layout_weight="1"
                android:gravity="center" 
                android:orientation="vertical">
    
                <TextView 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:textColor="@color/white"
                    android:textSize="18sp" 
                    android:textStyle="bold"
                    android:singleLine="true" 
                    android:text="text"/>
    
            </LinearLayout>
    
       </LinearLayout>
    
    
    
    您可以在画布上绘制图像,然后在图像上绘制文本,或者,通过代码创建布局,将textview设置在布局中,然后将布局放置在图像视图的顶部,textview的背景设置为透明

    您可以仅使用
    textview
    进行此操作。按以下方式使用
    drawableTop
    drawabletown
    drawabletleft
    drawabletright

    <TextView
        style="@style/layout_wrap"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:paddingRight="5dp"
        android:drawableTop="@drawable/flags_00"
        android:textColor="@color/text_color_tabs"
        android:textStyle="bold"
        android:maxLength="3"
        android:gravity="center"
        android:text="Team B" />
    

    您可以使用按钮和按钮背景设置图像,并使用文本元素在按钮上添加文本

       <Button
         android:layout_width="wrap_parent"
         android:layout_height="wrap_parent"
         android:text="YourText"
         android:background="@drawable/image"
        >
       </Button>
    
    
    

    根据您的要求,您可以从按钮中获取文本并有意传递它

    使用相对布局或框架布局如何将文本保存到图像上的不同字体?您可以使用不同的字体进行此操作。。。让我更新我的ans,然后如何在没有拖放位置的情况下自动在图像视图上保存文本?请检查更新的ans。。。只需将值传递给setText()方法。。你说的“没有拖放位置”是什么意思?文本不应该在版面中定义不同的用户以不同的方式键入他们的文本在图像视图中显示?然后使用android:visibility=“invisible”在版面中设置可见性并以编程方式使其可见。你能帮助我完成教程吗?
       <Button
         android:layout_width="wrap_parent"
         android:layout_height="wrap_parent"
         android:text="YourText"
         android:background="@drawable/image"
        >
       </Button>