I want to create a horizontal list of images that the user can add (and delete) dynamically, except for the first (it works like a button to add an image). The user will click on this first to add more photos to his left. As shown below, I am creating a horizontal scroll and linear layout that initially has one NetworkImageView, which is the button for the image adder.
In xml there is:
...
<HorizontalScrollView
android:id="@+id/horizontal_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.android.volley.toolbox.NetworkImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imageViewAdd"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:background="@color/colorAccent"
android:contentDescription="@string/description" />
</LinearLayout>
</HorizontalScrollView>
...
Then in the code, when the user clicks on this NetworkImageView, I want to add others in front of him one by one.
...
layout = (LinearLayout) findViewById(R.id.linear);
imageViewAdd = (NetworkImageView)findViewById(R.id.imageViewAdd);
ImageLoader imageLoader = CustomVolleyRequest.getInstance(this.getApplicationContext())
.getImageLoader();
imageLoader.get(Config.IMAGE_PATH_URL, ImageLoader.getImageListener(imageViewAdd,
R.drawable.image, android.R.drawable
.ic_menu_camera));
imageViewAdd.setImageUrl(Config.IMAGE_PATH_URL, imageLoader);
imageViewAdd.setOnClickListener(this);
totalImageCount = 0;
...
NetworkImageView newView = new NetworkImageView(this);
newView.setId(id);
newView.setPadding(2, 2, 2, 2);
newView.setScaleType(ImageView.ScaleType.FIT_XY);
layout.addView(newView, id);
ImageLoader imageLoader = CustomVolleyRequest.getInstance(this.getApplicationContext())
.getImageLoader();
imageLoader.get(Config.IMAGE_PATH_URL, ImageLoader.getImageListener(newView,
R.drawable.image, android.R.drawable
.ic_dialog_alert));
newView.setImageUrl(Config.IMAGE_PATH_URL, imageLoader);
newView.requestLayout();
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
(int) getResources().getDimension(R.dimen.imageview_height),
(int)getResources().getDimension(R.dimen.imageview_width));
newView.setLayoutParams(layoutParams);
...
Later in the code, when I really want to set the path to it, I read the width and height as follows:
int targetW = newView.getWidth();
int targetH = newView.getHeight();
0. SO, ( , 3 !).
!