Android 自定义控件 仿乐Phone UI

 

 

首页Linux编程

背景:

阅读新闻

Android 自定义控件 仿乐Phone UI

[日期:2010-09-27]   来源:Linux社区  作者:wallage   [字体:]  

本来想自己重新写个类似的UI,没想用snakeLayout就直接能成了,出乎意料,画了点时间设计好位置,
 
主文件:newSnake.java
package com.newSnake;
import Android.app.Activity;
import android.os.Bundle;
public class newSnake extends Activity {
    /** Called when the activity is first created. */
 SnakeLayout mSnake;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        mSnake = (SnakeLayout)findViewById(R.id.my_snake);
        mSnake.addRec(R.drawable.p0);
        mSnake.addRec(R.drawable.p1);
        mSnake.addRec(R.drawable.p2);
        mSnake.addRec(R.drawable.p3);
        mSnake.addRec(R.drawable.p4);
        mSnake.addRec(R.drawable.p5);
        mSnake.addRec(R.drawable.p6);
        mSnake.addRec(R.drawable.p7);
        mSnake.addRec(R.drawable.p8);
        mSnake.Init();
    }
}
 
布局文件:main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:snake="http://schemas.android.com/apk/res/com.newSnake"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:background="#FFFFFF">
 <com.newSnake.SnakeLayout android:layout_width="200dip" android:layout_weight="1"
     android:id="@+id/my_snake" android:layout_height="330dip"
     snake:selectImg="3">
     <FrameLayout android:layout_width="fill_parent" android:orientation="vertical"
      android:layout_height="wrap_content" android:id="@id/snakeContent">
      <ImageView android:layout_width="140dip" android:id="@id/snakeImg0"
       android:layout_height="60dip"
       android:paddingLeft="60dip"
       android:paddingTop="0dip"/>
      <ImageView android:layout_width="160dip" android:id="@id/snakeImg1"
       android:layout_height="105dip"
       android:paddingLeft="40dip"
       android:paddingTop="15dip"/>
      <ImageView android:layout_width="180dip" android:id="@id/snakeImg2"
       android:layout_height="165dip"
       android:paddingLeft="20dip"
       android:paddingTop="45dip"/>
      <ImageView android:layout_width="140dip" android:id="@id/snakeImg6"
       android:layout_height="330dip"
       android:paddingLeft="60dip"
       android:paddingTop="270dip"/>
      <ImageView android:layout_width="160dip" android:id="@id/snakeImg5"
       android:layout_height="315dip"
       android:paddingLeft="40dip"
       android:paddingTop="225dip"/>
      <ImageView android:layout_width="180dip" android:id="@id/snakeImg4"
       android:layout_height="285dip"
       android:paddingLeft="20dip"
       android:paddingTop="165dip"/>
      <ImageView android:layout_width="200dip" android:id="@id/snakeImg3"
       android:layout_height="240dip"
       android:paddingLeft="0dip"
       android:paddingTop="90dip"/>
     </FrameLayout>
    </com.newSnake.SnakeLayout>
</LinearLayout>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwsxds.html