bitmap - プログラムで textview を imageview Android に配置します

okwaves2024-01-25  9

イメージビューにテキストを配置しようとしていますが、プログラムでそれを行う方法がわかりません。 まず、firebase storage から画像をダウンロードし、次にこの画像をテキストを含むリニアレイアウトに配置したいと思います。このプロセスは、データベースに画像がある限り繰り返されます。

これは私のコードです: XML:

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical" >
        </LinearLayout>

    </ScrollView>

アクティビティからの関連コード:

                    fileRef.getFile(localFile)
                            .addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                                @RequiresApi(api = Build.VERSION_CODES.Q)
                                @Override
                                public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                                            LinearLayout.LayoutParams.MATCH_PARENT,
                                            LinearLayout.LayoutParams.WRAP_CONTENT);
                                    LinearLayout linearLayout = findViewById(R.id.linearLayout);
                                    Bitmap bitmap = BitmapFactory.decodeFile(finalLocalFile.getAbsolutePath());
                                    TextView textView = new TextView(GaleryActivity.this);
                                    textView.setText("Something");
                                    textView.setTextSize(24);
                                    Typeface typeFace = Typeface.createFromAsset(getAssets(), "aqua.ttf");
                                    textView.setTypeface(typeFace);
                                    textView.setGravity(Gravity.END|Gravity.BOTTOM);
                                    linearLayout.addView(textView);
                                    ImageView imageView = new ImageView(getApplicationContext());
                                    imageView.setBackground(GaleryActivity.this.getResources().getDrawable(R.drawable.mybutton));
                                    imageView.setImageBitmap(bitmap);
                                    linearLayout.addView(imageView,params);

なぜリサイクル業者ビューを使用せず、リサイクル業者アイテム モデル XML で処理するのですか?

– モハマド・デラクシャン

2020 年 9 月 3 日 16:00

これを試してみます、ありがとう

– ersa

2020 年 9 月 3 日 16:12



------------------------

LinearLayout はビューを 1 つずつ配置します。ビューをオーバーレイすることはできません。 FrameLayout を使用すると、ImageView の上に TextView を重ねることができます。または、多数のアイテムのリストがある場合は、RecyclerView を使用できます。

0

総合生活情報サイト - OKWAVES
総合生活情報サイト - OKWAVES
生活総合情報サイトokwaves(オールアバウト)。その道のプロ(専門家)が、日常生活をより豊かに快適にするノウハウから業界の最新動向、読み物コラムまで、多彩なコンテンツを発信。