【发布时间】:2018-07-06 22:18:18
【问题描述】:
在我的应用中,用户可以从图库中选择多张图片,然后他可以在应用中查看。
Relative Layout 中有三个按钮
<RelativeLayout 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.codenemesis.multipleimg.MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="imageSelector"
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="up"
android:text="Upload"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="viewclick"
android:text="View Images" />
为了显示我以编程方式在HorizontalScrollView 中创建的ImageView 数组设置为WRAP_CONTENT 的图像,但问题是当我单击查看按钮HorizontalScrollView 时跨越整个屏幕,如this。
我想在查看按钮下方显示HorizontalScrollView。我该怎么做?
这是我创建 HorizontalScrollView
的方法 HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
LinearLayout linearLayout = new LinearLayout(this);
ViewGroup.LayoutParams prams = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
linearLayout.setLayoutParams(prams);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
horizontalScrollView.addView(linearLayout);
// mArrayUri is the arraylist of images selected from gallery
int b = mArrayUri.size();
int c = 0;
ImageView[] imageViews = new ImageView[mArrayUri.size()];
while (c < mArrayUri.size()) {
imageViews[c] = new ImageView(this);
imageViews[c].setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
imageViews[c].setPadding(10,0,10,0);
imageViews[c].setImageURI(mArrayUri.get(c));
linearLayout.addView(imageViews[c]);
c++;
// Set context view
setContentView(horizontalScrollView);
【问题讨论】:
标签: java android android-layout horizontal-scrolling android-layoutparams