Android实现透明指示层-创新互联

以下仅为自己工作记录,方便今后查阅

创新互联服务项目包括象山网站建设、象山网站制作、象山网页制作以及象山网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,象山网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到象山省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

第一步:从原理上,了解这个功能,我们使用RelativeLayout 布局,然后在主页面内容之后,直接加入指示层如下代码。

<RelativeLayout android:orientation="vertical"android:background="#ffe4e4e4" android:layout_width="fill_parent"android:layout_height="fill_parent"

  xmlns:android="http://schemas.android.com/apk/res/android">

  <LinearLayout android:orientation="vertical"android:background="#ffe4e4e4" android:layout_width="fill_parent"android:layout_height="fill_parent"

    <include layout="@layout/hotel_details_head"

    <ListView android:id="@id/hotel_detail_rooms"android:fadingEdgeLength="5.0dip" android:layout_width="fill_parent"android:layout_height="wrap_content" android:listSelector="#00000000"android:cacheColorHint="#00000000" android:divider="#00ffffff"android:dividerHeight="1.0dip"

    </LinearLayout

    <

    android:src="@drawable/tip1"

    android:layout_height="fill_parent"

    android:layout_width="fill_parent"

    android:id="@+id/helpTipbackground"

    android:scaleType="centerInside"

    android:keepScreenOn="true"

    android:visibility="gone"

  />

    <

    android:src="@drawable/thisred"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:id="@+id/helpTip"

    android:scaleType="center"

    android:visibility="gone"

  />

</RelativeLayout

解释:linearlayout是主要显示的内容,而下面的两个p_w_picpathview是用来指示的图层。这里我使用指示层和解释层分开的方式,因为我发现android不同尺寸的屏幕如果只用一层太不好弄啦,也可以合并到一层根据个人需求自行决定,如果是一层那就不需要两个p_w_picpathview了。我们可以先将它们隐藏( android:visibility="gone"),等到主页面正常显示出来在将指示层显示出来。

第二步:添加activity代码,实现点击图层变化解释层的图标和指示层的位置。

private ImageView helpTipIV;//手指

private ImageView helpTipBackIV;//手指背景

private int backpicture=0;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_hotel_detail);

helpTipIV=(ImageView)this.findViewById(R.id.helpTip);

helpTipIV.setOnClickListener(this);

int[]xy = new int[2];

hotel_detail_save_iconIV.getLocationOnScreen(xy);

int x=xy[0];

int y=xy[1];

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(300,350);

params.setMargins(x-90, y+20, 0, 0);

helpTipIV.setLayoutParams(params);

helpTipBackIV=(ImageView)this.findViewById(R.id.helpTipbackground);

helpTipBackIV.setOnClickListener(this);

hotel_details_locationTV= (LinearLayout)hotelroomheader.findViewById(R.id.hotel_details_location);

}

@Override

public void onClick(View view) {

// TODO Auto-generated method stub

   int i=view.getId();

            switch(view.getId())

{

case R.id.helpTipbackground:{

if(backpicture==0)

{

helpTipBackIV.setImageResource(R.drawable.tip2);

int[]xy = new int[2];

hotel_details_locationTV.getLocationOnScreen(xy);

int x=xy[0];

int y=xy[1];

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(300,350);

params.setMargins(x, y+20, 0, 0);

helpTipIV.setLayoutParams(params);

backpicture++;

}else

{

helpTipBackIV.setVisibility(View.GONE);

helpTipIV.setVisibility(View.GONE);

}

helpTipBackIV.setImageResource(R.drawable.tip2);

break;

}

}

}

解释:在初始化界面成功后,先给手指层定义第一个指示的位置,然后给背景层添加点击事件,这里的onclick()方法是定义在父类中的,也可以直接为p_w_picpathview控件添加点击事件。这里要强调一下,原来我用的给控件定位的方法是setLeft()、setTop()、setRight()、setBottom()。这个方式如果对应一个图层的时候没有问题,但是对应两层的时候,如果其中一层调用了setImageResource()方法,另一侧会莫名其妙的变回到初始位置,由于我也是菜鸟不是很了解其中具体的原因,大概可能就是因为setImageResource()方法会重新初始化下另一个p_w_picpathview吧,总之用RelativeLayout.LayoutParams 是比较稳妥的方法。

这样运行之后,界面一开始没有指示层,直到显示出需要的界面后,指示层才出现,指示层会在需要解释的功能按钮旁边起到指示的作用,而解释层则会覆盖全部界面,当点击覆盖全部界面的解释层的时候,指示层改变位置,解释层更换下一张解释图片,OK大功告成。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

网页名称:Android实现透明指示层-创新互联
URL分享:https://www.cdcxhl.com/article4/ceegie.html

成都网站建设公司_创新互联,为您提供小程序开发营销型网站建设ChatGPT虚拟主机外贸建站微信公众号

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站网页设计