Question:
Good morning people. I have a problem that I can't solve, I've done a lot on the posts here and in the youtube tutorials and nothing. I'm developing an android app for a project in college, but I'm not a programmer, I decided to use the app to learn it.
What I need is to open an image that is in drawable in a lightbox by clicking a button.
this is my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.editoratracos.jogotracos.hd"
android:background="@drawable/fundo"
android:id="@+id/telahd"
>
<ImageButton
android:id="@+id/botaoNovo3"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="8dp"
android:background="@null"
android:onClick="chamaNovo"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:srcCompat="@drawable/novojogo"
android:layout_marginRight="70dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="70dp" />
<ImageButton
android:id="@+id/botaoComo2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="10dp"
android:background="@null"
android:onClick="chamaComo"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/comojogar"
android:layout_marginEnd="10dp" />
<ImageButton
android:id="@+id/botaoHome"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="10dp"
android:background="@null"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:srcCompat="@drawable/home"
android:onClick="chamaHome"
android:layout_marginStart="10dp" />
<ScrollView
android:layout_width="368dp"
android:layout_height="400dp"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="1.0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="600dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<ImageView
android:id="@+id/iconAla"
android:layout_width="60dp"
android:layout_height="60dp"
android:adjustViewBounds="true"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ala"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/iconAyao"
android:layout_marginEnd="10dp"/>
<ImageView
android:id="@+id/iconAyao"
android:layout_width="60dp"
android:layout_height="60dp"
android:adjustViewBounds="true"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ayao"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/iconBunzi"
android:layout_marginEnd="10dp"/>
<ImageView
android:id="@+id/iconBunzi"
android:layout_width="60dp"
android:layout_height="60dp"
android:adjustViewBounds="true"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/bunzi"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/iconGleti"
android:layout_width="60dp"
android:layout_height="60dp"
android:adjustViewBounds="true"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/gleti"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/iconBunzi"
android:layout_marginStart="10dp" />
<ImageView
android:id="@+id/iconIemanja"
android:layout_width="60dp"
android:layout_height="60dp"
android:adjustViewBounds="true"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/iemanja"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/iconGleti"
android:layout_marginStart="10dp" />
<ImageView
android:id="@+id/iconMbaba"
android:layout_width="60dp"
android:layout_height="60dp"
android:adjustViewBounds="true"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/mbaba"
android:layout_below="@+id/iconAla"
android:layout_alignStart="@+id/iconAla"
android:layout_marginTop="10dp" />
</RelativeLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
and this is my class:
package com.editoratracos.jogotracos;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class hd extends AppCompatActivity {
@Override
public void onBackPressed(){
startActivity(new Intent(this, hd.class));
finishAffinity();
return;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hd);
}
public void chamaComo(View v) {setContentView(R.layout.activity_como);}
public void chamaHD(View v) {setContentView(R.layout.activity_hd);}
public void chamaNovo (View v) {setContentView(R.layout.activity_novo);}
public void chamaSobre (View v) {setContentView(R.layout.activity_sobre);}
public void chamaComecar (View v) {setContentView(R.layout.activity_comecar);}
public void chamaHome (View v) {setContentView(R.layout.activity_inicial);}
}
Answer:
You can do as follows, create an Activity with transparent background, place the imageView and textView component at the bottom, and when you click on the photo, you start this Activity ("TransparentActivity") passing the image data with the
nome_da_intent.putExtra("img", "teste")
and take the other Activity with the
Bundle bundle = getIntent().getExtras();
String img = bundle.getString("img");
and then put it in the imageView and the caption in the textView or if you prefer something simpler you can use AlertDialog, follow the documentation in this link:
https://developer.android.com/guide/topics/ui/dialogs.html?hl=pt-br