今天来介绍下一个app的第一个页面广告页,广告页是app的第一个页面。lOGO页面的跳转分为三类,1.点击跳转2.定时跳转3.动画播放完毕自动跳转,下面都进行介绍一遍。

1.首先是点击跳转:还是先把布局放出来,点击跳转是最简单的一个intent就解决了。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        >

        <ImageView
            android:id="@+id/imagelogo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/logo11"
            />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50sp"

        android:weightSum="1"
        android:layout_alignParentBottom="true"
        android:background="#2e0255fc"

        android:orientation="horizontal">
        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/logo21"
            android:layout_weight="0.2"
            android:paddingLeft="30sp"
            />


        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="match_parent"

            android:layout_weight="0.3"
            android:text="宾尼 匹斯堡"
            android:gravity="center_vertical"
            android:textColor="#0a0a0a"
            android:textSize="18sp"
            />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="0dp"
            android:layout_height="match_parent"

            android:layout_weight="0.2"
            android:paddingTop="14sp"
            android:text="进入"

            android:gravity="right"
            android:textColor="#030303"
            android:textSize="18sp"
            />
        <RadioButton
            android:id="@+id/radioButton"
            android:layout_width="0sp"
            android:layout_height="match_parent"
            android:layout_weight="0.3"
            android:gravity="center"
            android:button="@null"


            />

    </LinearLayout>



</RelativeLayout>
整个布局是一个相对布局,Relativelayout,里面有两个linelayout,第一个充满父亲,第二个,在父亲的底部,同时把第二个设置为半透明。
这个logo页面的布局layout,由于底部有一个按钮用于跳转的在<RadioButton>里面其大小位置不满足我们的想法,所以在activty里面对其进行了调试代码待会会发出来。
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50sp"
        android:weightSum="1"
        android:layout_alignParentBottom="true"//将布局置于底部
        android:background="#2e0255fc"//背景色可视透
        
        android:orientation="horizontal">
这个是什么下面设计的一个<Radiobutton>按钮

<RadioButton
    android:id="@+id/radioButton"
    android:layout_width="0sp"
    android:layout_height="match_parent"
    android:layout_weight="0.3"
    android:gravity="center"
    android:button="@null"//把背景图取消掉

   //图片显示在那个按钮的右边,但是由于显示的图片始终达不到想要的位置和大小,需要在activty里面进行对其设定
    />

这个就是对按钮的设定代码,首先找到这个logo,这个logo是一个图片选择器
Drawable drawableWeiHui = getResources().getDrawable(R.drawable.logo);
drawableWeiHui.setBounds(10, 30, 150, 150);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度
rb7.setCompoundDrawables(drawableWeiHui,null,  null, null);//只放上面
RadioButton rb7=(RadioButton)findViewById(R.id.radioButton);

这个logo我在Drawable文件下建立了一个logo.xml是一个选择器看代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true" android:drawable="@drawable/logo34">

    </item>
    <item
        android:state_pressed="false" android:drawable="@drawable/logo32">

    </item>
</selector>这个就是一个图片选择器有两个标签<selector><item><item>里面有两个状态,表示没有点击和点击分别显示的图片。这样布局大概就步好了,下面介绍功能。1.定时操作跳转:用线程,同时需要注意
public class LogoActivty extends BaseActivity {
RadioButton rb7=(RadioButton)findViewById(R.id.radioButton);
private Handler handler=new Handler()
{
    @Override
    public void handleMessage(Message msg) {
       
        rb7.setText(msg.what+"s");
    }
};    @Override    
public void setview()    
{  
          //加载这个logo  
       setContentView(R.layout.logo);        
      if(Utilshard.getserrion(this))
       {            
            Utilshard.saveserrion(this); 
            Intent in=new Intent(LogoActivty.this,LeadActivity.class); 
            startActivity(in);            
            finish(); 
       }else        {
                   //用线程来设定睡三秒,for循环外面进行跳转完了之后跳转,每一秒进行修改值。三秒以后自动跳转。如果这个时候在子线程中对button或者什么进行了修改值,就会出现子线程不能修改主线程的控件的错误,这个时候需要用到线程间通信。handler,
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for(int i=3;i>0;i--)
                        {
//在这里发送消息有两种方法,一种直接发空消息,不需要Message对象,另一种是需要发对象,同时上面需要new Handler对象,同时重写hanlermessege方法。在这个时候还需要对message进行优化,因为如果一直new Message对象,这样对内存的代价太大,所以需要优化调用它的静态方法;obtain()就可以了
                            //Message mse=new Message();                             Message mse=Message.obtain();                             mse.what=1;                             handler.sendMessage(mse);                              
//                            handler.sendEmptyMessage(i);                            try {  
                                   Thread.sleep(1000);
                                } catch (InterruptedException e) 
                                {                                
                                   e.printStackTrace(); 
                                }                       
                                }                        
                                   gotomain();//跳转到主页 
                                 }                
                               }).start(); 
                                 }  
              //这个地方同时写了一个个手动点击跳转,所以这个时候会出现两次跳转现象,就会出现两个主页的现象,为了避免这个问题,我们把跳转的方法进行了封装,同时将设立一个布尔值,同时给这个跳转的方法设立了一个线程锁,这个时候,就也可以防止多线程的问题,只要执行了一次,那么这个方法就可以不执行了,因为布尔值已经变为false了。       
 rb7.setOnClickListener(new View.OnClickListener() { 
           @Override            
           public void onClick(View v) {
                TextView rb8=(TextView)findViewById(R.id.textView3);                               rb8.setTextColor(getResources().getColor(R.color.colorPrimary));                      gotomain();
            }       
           });        
Drawable drawableWeiHui = getResources().getDrawable(R.drawable.logo);
drawableWeiHui.setBounds(10, 30, 150, 150);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度        
rb7.setCompoundDrawables(drawableWeiHui,null,  null, null);
//只放上面   
 }
    @Override 
   public void initview()    {    } 
   boolean fla=true;        
//gotomain()方法跳转到主页。 
   public synchronized void gotomain() 
   {        
      if(fla) {  
           fla=false; 
           Intent in = new Intent(LogoActivty.this, MainActivity.class);                        startActivity(in); 
       }   
 }}