作者共發了2篇帖子。 內容轉換:不轉換▼
 
點擊 回復
173 1
今天我学习了安卓界面的其他布局方式以及notification
一派護法 十九級
1樓 發表于:2015-1-2 14:39
package com.example.users;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class Act2 extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_act2);
        
        OnClickListener btn_events = new OnClickListener() {
            @SuppressLint("NewApi") @Override
            public void onClick(View v)
            {
                ImageView img = (ImageView)findViewById(R.id.imageView2);
                int l = img.getLeft();
                int t = img.getTop();
                int r = img.getRight();
                int b = img.getBottom();
                
                switch (v.getId())
                {
                case R.id.button1:
                    t--;
                    l--;
                    break;
                case R.id.button3:
                    t--;
                    l++;
                    break;
                case R.id.button4:
                    t++;
                    l--;
                    break;
                case R.id.button5:
                    t++;
                    l++;
                    break;
                case R.id.button2:
                    Notification.Builder m = new Notification.Builder(Act2.this);
                    m.setSmallIcon(R.drawable.p2);
                    m.setContentTitle("Arslanbar");
                    //m.setOngoing(true);
                    m.setContentText("The app is under construction.");
                    
                    NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                    nm.cancelAll();
                    nm.notify(1, m.build());
                    break;
                }
                img.layout(l, t, r, b);
            }
        };
        findViewById(R.id.button1).setOnClickListener(btn_events);
        findViewById(R.id.button2).setOnClickListener(btn_events);
        findViewById(R.id.button3).setOnClickListener(btn_events);
        findViewById(R.id.button4).setOnClickListener(btn_events);
        findViewById(R.id.button5).setOnClickListener(btn_events);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.act2, menu);
        return true;
    }

}

一派護法 十九級
2樓 發表于:2015-1-2 14:39
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top|center"
    android:gravity="top|left"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Act2" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="@string/A" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button1"
            android:layout_centerInParent="true"
            android:layout_toRightOf="@+id/button1"
            android:text="@string/C" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button2"
            android:layout_toRightOf="@+id/button2"
            android:text="@string/B" />

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button2"
            android:layout_toLeftOf="@+id/button2"
            android:text="@string/D" />

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button2"
            android:layout_toRightOf="@+id/button2"
            android:text="@string/E" />

    </RelativeLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/A"
            android:src="@drawable/p1" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center"
            android:contentDescription="@string/C"
            android:src="@drawable/p3" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="28dp"
            android:layout_marginTop="40dp"
            android:contentDescription="@string/B"
            android:src="@drawable/p2" />

    </FrameLayout>

</LinearLayout>

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:173 回複數:1
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2015-1-2 14:39
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。