如何在Android中利用TextView实现自定义竖排-创新互联
这篇文章给大家介绍如何在Android中利用TextView实现自定义竖排,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
成都创新互联凭借在网站建设、网站推广领域领先的技术能力和多年的行业经验,为客户提供超值的营销型网站建设服务,我们始终认为:好的营销型网站就是好的业务员。我们已成功为企业单位、个人等客户提供了成都网站设计、成都网站建设、外贸网站建设服务,以良好的商业信誉,完善的服务及深厚的技术力量处于同行领先地位。测试用的Activity。
public class MainActivity extends Activity implements OnTouchListener { private VerticalTextView mVerticalTextView; private TextView mTextView; private int mTextCount; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); mVerticalTextView = (VerticalTextView) findViewById(R.id.vertical_tv); mTextView = (TextView) findViewById(R.id.content_tx); mTextCount = mVerticalTextView.getText().length(); mVerticalTextView.setOnTouchListener(this); mTextView.setBackgroundColor(Color.LTGRAY); } @Override public boolean onTouch(View v, MotionEvent event) { float verticalTextViewHeight = mVerticalTextView.getHeight(); float y = event.getY(); int sectionPosition = (int) Math.ceil((y / verticalTextViewHeight) / (1f / mTextCount)) - 1; if (sectionPosition < 0) { sectionPosition = 0; } else if (sectionPosition >= mTextCount) { sectionPosition = mTextCount - 1; } String sectionLetter = String.valueOf(mVerticalTextView.getText() .charAt(sectionPosition)); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTextView.setVisibility(View.VISIBLE); mTextView.setText(sectionLetter); break; case MotionEvent.ACTION_MOVE: mTextView.setText(sectionLetter); mTextView.setVisibility(View.VISIBLE); break; case MotionEvent.ACTION_UP: mTextView.setVisibility(View.INVISIBLE); default: break; } return true; } }
新闻名称:如何在Android中利用TextView实现自定义竖排-创新互联
URL分享:http://pwwzsj.com/article/djhhii.html