自定义控件:飞入飞出的效果

本文介绍如何使用StellarMap控件实现滚动显示不同层级的文本内容效果。通过四个关键步骤:复制类文件、创建布局文件、设置Adapter适配器及配置StellarMap参数,轻松实现动态文本展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图:


  用到4个类(copy)

1 布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <com.baidu.stellarmap.lib.StellarMap
        android:id="@+id/stleeMap"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

 

 * 步骤:
 *  准备:复制4个类
 *  1 布局+获取StellarMap对象
 *  2 设置adapter
 *  3 设置StellarMap参数

*  1 布局+获取StellarMap对象

//1获取StellarMap对象
		stellarMap = (StellarMap) findViewById(R.id.stleeMap);

 

*  2 设置adapter

//2 设置adapter
		MyAdapter adapter = new MyAdapter();
		stellarMap.setAdapter(adapter);


 

class MyAdapter implements Adapter {// 注意:Adapter是stellMap包下的,是interface

		// 共多少组数据
		@Override
		public int getGroupCount() {
			return 3;
		}

		// 每一组有多少条数据
		@Override
		public int getCount(int group) {
			return 11;
		}

		@Override
		public View getView(int group, int position, View convertView) {
			TextView tv = new TextView(context);
			tv.setText("item" + position);
			// 1 设置字体大小
			Random random = new Random();
			int textSize = random.nextInt(8) + 15;
			tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);

			// 2 设置字体颜色
			int red = random.nextInt(150) + 50;
			int green = random.nextInt(150) + 50;
			int blue = random.nextInt(150) + 50;
			int textColor = Color.rgb(red, green, blue);
			tv.setTextColor(textColor);

			return tv;
		}

		// 没什么作用
		@Override
		public int getNextGroupOnPan(int group, float degree) {
			return 0;
		}

		// 下一个页面要显示的数据
		@Override
		public int getNextGroupOnZoom(int group, boolean isZoomIn) {
			return (group + 1) % getGroupCount();// 确保循环显示
		}
	}


 

 3 设置StellarMap参数

若想第一页就显示数据,那么方法setGroup(0, true);必须放在setAdapter(adapter)后面,其他方法顺序无所谓;

public void initStellarMap() {
		stellarMap.setGroup(0, true);
		stellarMap.setInnerPadding(padding, padding, padding, padding);// 设置textView的内边距
		stellarMap.setRegularity(15, 15);
	}



源码:http://download.youkuaiyun.com/detail/ss1168805219/9485126

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值