イメージビューにテキストを配置しようとしていますが、プログラムでそれを行う方法がわかりません。
まず、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