Android Studio에서..imageview....왕초보입니다
조회수 1099회
원래 계획은 main액티비티에는 Button이 하나만 있고, 클릭 후 전환될 액티비티에는 사진들이 있는 UI를 만들어보려고 했습니다...근데 그 과정에서 잘모르는 부분이 생겨 질문드립니다...ㅠㅠㅠㅠ
intent를 활용해 2번째 액티비티로 이동하는건 되는데 2번째 액티비티와 연결돼있는 xml에 추가한 이미지파일이 안보이는 문제입니다. (혹시나 싶어 버튼을 넣어봤는데 버튼은 또 잘나오더라구요!..?)
이미지뷰나 스크롤뷰가 문제가있나싶어서 2번째 액티비티에 있는 코드를 메인페이지에 ctrl C+V해봤는데 main화면에서는 아주잘나오네.. (현재 코드상태)
intent로 다음화면을 넘어갔을때 textview 나 button은 나오면서 왜 imageview는 적용이 안될까요???
첫번째 메인액티비티
public class MainActivity extends AppCompatActivity {
Button btn1 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button)findViewById(R.id.Btn);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent1 = new Intent(getApplicationContext(),AfterActivity.class);
startActivity(intent1);
}
});
}
연결된 xml
<?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.jjj.zzz.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:text="클릭하면 다음화면으로"
android:textSize="10pt"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center|top"
/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/pic1"
android:contentDescription="사진1"/>
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/pic2"
android:contentDescription="사진2"/>
</LinearLayout>
</ScrollView>
전환 후나올 2번째 액티비티
public class AfterActivity extends Activity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_after);
}
}
2번째 액티비티 xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.jjj.zzz.AfterActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/Btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:text="이미지파일이 안나옴.."
android:textSize="10pt"
android:layout_marginTop="15dp"
android:layout_gravity="center|top"
/>
<ImageView
android:id="@+id/imageView0"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/pic1"
android:contentDescription="사진1"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력