Code for How to create a storybook on the Android ... - Partlan Group

kingfishblacksmithMobile - sans fil

14 déc. 2013 (il y a 3 années et 6 mois)

126 vue(s)

Page1.xml

<?
xml

version
=
"1.0"

encoding
=
"utf
-
8"
?>

<
RelativeLayout

xmlns:android
=
"http://schemas.android.com/apk/res/android"


android:background
=
"#CC0000"



android:layout_width
=
"fill_parent"


android:layout_height
=
"fill_parent"
>




<
Button


android:id
=
"@+id/next"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentBottom
=
"true"


android:layout_alignParentRight
=
"true"


android:text
=
"Next"

/>



<
Button


android:id
=
"@+id/previous"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentLeft
=
"true"


android:layout_alignTop
=
"@id/next"


android:text
=
"Previous"

/>


<
ImageView





android:id
=
"
@+id/abookpage1"




android:layout_above
=
"@id/next"




android:layout_centerHorizontal
=
"true"




android:src
=
"@drawable/abookpage1"




android:layout_width
=
"wrap_content"




android:layout_height
=
"wrap_content"

/>

</
RelativeLayout
>



Page 2.xml

<?
xml

version
=
"1.0"

encoding
=
"utf
-
8"
?>

<
RelativeLayout

xmlns:android
=
"http://schemas.android.com/apk/res/android"


android:background
=
"#627F3A"



android:layout_width
=
"fill_parent"


android:layout_height
=
"fill_parent"
>




<
Button


an
droid:id
=
"@+id/next"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentBottom
=
"true"


android:layout_alignParentRight
=
"true"


android:text
=
"Next"

/>



<
Button


android:id
=
"@+id/previous"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentLeft
=
"true"


android:layout_alignTop
=
"@id/next"


android:text
=
"Previous"

/>


<
ImageView





android:id
=
"@+id/abookpage2"




android:layout_above
=
"@id/next"




android:layout_centerHorizontal
=
"true"




android:src
=
"@drawable/abookpage2"




android:layout_width
=
"wrap_content"




android:layout_height
=
"wrap_content"

/>

</
RelativeLayout
>



Page3.xml

<?
xml

version
=
"1.0"

encoding
=
"utf
-
8"
?>

<
RelativeLayout

xmlns:android
=
"http://schemas.android.com/apk/res/android"


android:background
=
"#DCCD29"



android:layout_width
=
"fill_parent"


android:layout_height
=
"fill_parent"
>




<
Button


android:id
=
"@+id/next"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentBottom
=
"true"


android:layout_alignParentRight
=
"true"


android:text
=
"Next"

/>



<
Button


android:id
=
"@+id/previous"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentLeft
=
"true"


android:layout_alignTop
=
"@id/next"


android:text
=
"Previous"

/>


<
ImageView





android:id
=
"@+id/abookpage3"




android:layout_above
=
"@id/next"




android:layout_centerHorizontal
=
"true"




android:src
=
"@drawable/abookpage3"




android:layout_width
=
"wrap_content"




android:layout_height
=
"wrap_content"

/>

</
RelativeLayout
>


page4.xml

<?
xml

version
=
"1.0"

encoding
=
"utf
-
8"
?>

<
RelativeLayout

xmlns:android
=
"http://schemas.android.com/apk/res/android"


android:background
=
"#8A4C56"



android:layout_width
=
"fill_parent"


android:layout_height
=
"fill_parent"
>




<
Button


android:id
=
"@+id/next"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentBottom
=
"true"


android:layout_alignParentRight
=
"true"


android:text
=
"Next"

/>



<
Button


android:id
=
"@+id/previous"


android:layout_width
=
"80dip"


android:layout_height
=
"35dip"


android:layout_alignParentLeft
=
"true"


android:layout_alignTop
=
"@id/next"


android:text
=
"Previous"

/>


<
ImageView





android:id
=
"@+id/abookpage4"




android:layout_above
=
"@id/next"




android:layout_centerHorizontal
=
"true"




android:src
=
"@drawable/abookpage4"




android:layout_width
=
"wrap_content"




android:layout_height
=
"wrap_content"

/>

</
RelativeLayout
>



StoryBook
.java

package example.storybook.one;



import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

import android.view.View.OnClickListener;

import android.widget.Button;


public class StoryBook extends Activity {



/** Called when the activity is first created. */


private int index = 1;


private Button nextButton;


private Button previousButton;






@Override

//===============================================
==============================





public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);





requestWindowFeature(Window.FEATURE_NO_TITLE);


getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLS
CREEN,


WindowManager.LayoutParams.FLAG_FULLSCREEN);



updateview();


} //end onCreate

//=============================================================================

private void updateview(){




if (index>=5) index = 1;


if

(index<=0) index = 4;





if (index==1) {




this.setContentView(R.layout.page1);nextprocess();previousprocess();};



if (index==2) {




this.setContentView(R.layout.page2);nextprocess();previousprocess();};



if (index==3) {





this.setContentView
(R.layout.page3);nextprocess();previousprocess();};



if (index==4) {





this.setContentView(R.layout.page4);nextprocess();previousprocess();};

}// end updateview

//=============================================================================

private
void nextprocess(){



this.nextButton = (Button)this.findViewById(R.id.next);


this.nextButton.setOnClickListener(new OnClickListener() {


@Override


public void onClick(View v) {



index = index+1;



updateview();


}


});

}// end nextprocess

//=============================================================================

private void previousprocess(){




this.previousButton = (Button)this.findViewById(R.id.previous);


this.previousButton.setOnClickListener
(new OnClickListener() {


@Override


public void onClick(View v) {


index = index
-
1;



updateview();


}}


);

} // end previouseprocess

//===========================================================================
==

}//end class Story Book


AndroidManifest.xml

<?
xml

version
=
"1.0"

encoding
=
"utf
-
8"
?>

<
manifest

xmlns:android
=
"http://schemas.android.com/apk/res/android"


package
=
"example.storybook.one"


android:versionCode
=
"1"


android:versionName
=
"1.0"
>


<
application

android:icon
=
"@drawable/icon"

android:label
=
"@string/app_name"
>


<
activity

android:name
=
".StoryBook"


android:screenOrientation
=
"landscape"


android:label
=
"@string/app_name"
>


<
intent
-
filter
>


<
action

android:name
=
"android.intent.action.MAIN"

/>


<
category

android:name
=
"android.intent.category.LAUNCHER"

/>


</
intent
-
filter
>


</
activity
>



</
application
>



</
manifest
>