레이아웃에서 2 개의 imagview를 추가하고 싶은 안드로이드 앱을 개발 중입니다. 레이아웃에 레이아웃이 있습니다. 사용자가 사진을 찍을 때 사진을 찍을 때 하나의 이미지 뷰가 추가됩니다. 사진에서 카메라에서 사진을 얻을 때 그 imageview에서 그것을 보여줄 것입니다 그리고 그 imageview는 오른쪽 모서리에 하나의 십자가 ImageButton이 있습니다. 이미지가로드되면 똑같은 것이 제가 추가하고 싶은 또 다른 imageview에 대해 일어날 것입니다 사용자가 사진을 클릭하지만 동적으로 추가하는 방법을 모른다. 나는 대답을 검색 하나 layoutview.Please이 문제와 함께 나를 도울 이미지 뷰 추가됩니다. 널 자녀를 추가 할 수 없습니다 : 내 XML과 자바 코드 만 가지고 오류안드로이드에서 레이아웃에 2 개의 이미지 뷰를 동적으로 추가하는 방법
java.lang.IllegalArgumentException가 업데이트 Vijendra에 의해 주어진 솔루션에 따라
내가이 as show in this image the imageview has cross button on it
처럼 원하는 뷰 그룹 여기
에보기 내 main.xml
입니다 :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bicycle_broken_layout">
<EditText
android:id="@+id/et_moreinfo_broken_bike"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="15dp"
android:hint="@string/more_info"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:background="@color/ch_bg"
android:paddingTop="5dp"
android:lines="3"
android:gravity="top|left"
android:inputType="textMultiLine"/>
<RelativeLayout
android:id="@+id/broken_image_photos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et_moreinfo_broken_bike"
android:layout_marginTop="20dp">
</RelativeLayout>
<Button
android:id="@+id/btn_submit_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/broken_image_photos"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:background="@color/bg_main"
android:text="@string/submit_button"
android:textSize="17sp"
android:textColor="@color/white"
android:padding="15dp"/>
</RelativeLayout>
및 자바 코드에 XML
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/multipleimages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
//add your imageview here programatically
</LinearLayout>
</HorizontalScrollView>
에서 mainactivity.java
public class Broken_Report_Activity extends AppCompatActivity implements
View.OnClickListener {
private EditText broken_bike_number,broken_bike_location,more_info;
private Button barcode_scanner,location;
private Button submit_report;
private CheckBox seat,pedals,breaks,lock,chain,tier;
private Imageview_add_dynamically photo1,close_photo,framlayout;
RelativeLayout broken_image_layout;
private boolean Isphoto1=false,Isphoto2=false,Isphoto3=false;
private static final int CAMERA_REQUEST = 1888;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_broken_report);
broken_bike_number = (EditText)findViewById(R.id.et_broken_bike_number);
broken_bike_location =
(EditText)findViewById(R.id.et_broken_bike_location);
more_info = (EditText)findViewById(R.id.et_moreinfo_broken_bike);
submit_report = (Button)findViewById(R.id.btn_submit_report);
seat = (CheckBox)findViewById(R.id.ch_seat);
lock = (CheckBox)findViewById(R.id.ch_lock);
chain = (CheckBox)findViewById(R.id.ch_chain);
breaks = (CheckBox)findViewById(R.id.ch_break);
pedals = (CheckBox)findViewById(R.id.ch_pedals);
tier = (CheckBox)findViewById(R.id.ch_tire);
broken_image_layout =
(RelativeLayout)findViewById(R.id.broken_image_photos);
broken_image_layout.addView(photo1);
broken_image_layout.addView(close_photo);
photo1.setOnClickListener(this);
close_photo.setOnClickListener(this);
submit_report.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.broken_img1:
Intent broken_imag_1 = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(broken_imag_1,CAMERA_REQUEST);
break;
case R.id.broken_img1_close:
broken_image_layout.removeView(photo1);
broken_image_layout.removeView(close_photo);
break;
case R.id.btn_submit_report:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode,resultCode,data);
if(requestCode == CAMERA_REQUEST && resultCode == RESULT_OK){
Bitmap photo = (Bitmap)data.getExtras().get("data");
photo1.getImgPhoto().setImageBitmap(photo);
}
}
, 당신이 원하는 사진을 게시하시기 바랍니다. 아마도'RelativeLayout'을 사용하여 2 개의 ImageView를 추가해야 할 것입니다. 무엇을 원하니? 코드? – CoolMind
내 질문을 @CoolMind 업데이트했습니다. 동일한 방법이지만 동적으로 원합니다. –
RelativeLayout을 만들고 Topmargin (사진)으로 ImageView를 배치하고 오른쪽 상단 구석에 다른 ImageView (십자형)를 배치하십시오. 사진 만 표시하려면 십자 기호의 표시 여부를 INVISIBLE 또는 GONE으로 설정하십시오. 십자가를 표시하려면 가시성을 VISIBLE로 설정하십시오. onClick 이벤트를 추가하십시오. – CoolMind