【发布时间】:2018-02-05 05:26:57
【问题描述】:
我以编程方式在HorizontalScrollView 中设置了多个图像。当您单击HorizontalScrollView 中的该图像时,它会显示一个大图像视图,单击图像将突出显示然后滑动图像。
像图像切换器一样,它会在HorizontalScrollView 中突出显示。帮我解决一下代码,对我的项目很有用
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/horizontal">
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:layout_marginTop="60dp"
android:layout_width="match_parent"
android:layout_height="300dp" />
MainActivity
public class MainActivity extends AppCompatActivity {
private static final int RESULT_LOAD_IMAGE = 1;
private TextView deis;
private Button choose;
private LayoutInflater mInflater;
private LinearLayout mlinear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
deis=(TextView)findViewById(R.id.textview);
choose=(Button)findViewById(R.id.button);
mInflater = LayoutInflater.from(this);
choose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), RESULT_LOAD_IMAGE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK){
if(data.getClipData() != null){
int totalItemsSelected = data.getClipData().getItemCount();
for(int i = 0; i < totalItemsSelected; i++){
Uri fileUri = data.getClipData().getItemAt(i).getUri();
mlinear=(LinearLayout)findViewById(R.id.linear);
}
//Toast.makeText(MainActivity.this, "Selected Multiple Files"+fileUri, Toast.LENGTH_SHORT).show();
}
【问题讨论】:
标签: android android-layout horizontalscrollview