Android   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 添加到ImageView的Web链接?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

是否有可能(以及如何)ImageView链接到网页,以便用户点击图片时,它会将他们带到网页?我已经建立了这个结构,我需要每个ImageView的Web链接

<ScrollView
 <LinearLayout     
  <ImageView1
  <ImageView2
  <ImageView3
    .  
    . 
    .
 </LinearLayout>

</ScrollView>

解决方法:

您只需要一个onClick事件来处理所有ImageView点击.

使用android:tag@L_262_7@分配要打开的URl.
使用android:onClickattribute分配处理click事件的方法.

在xml中:

<ImageView
    android:id="@+id/image1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/yourimage1" 
    android:tag="http://site_1.com"
    android:onClick="openBrowser"/>  

<ImageView
    android:id="@+id/image2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/yourimage2" 
    android:tag="http://site_2.com"
    android:onClick="openBrowser"/>  

在活动中:

public void openBrowser(View view){

    //Get url from tag
    String url = (String)view.getTag();

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);

    //pass the url to intent data
    intent.setData(Uri.parse(url));

    startActivity(intent);
}

大佬总结

以上是大佬教程为你收集整理的android – 添加到ImageView的Web链接?全部内容,希望文章能够帮你解决android – 添加到ImageView的Web链接?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: