2.7-andridstudio installation project to establish three kinds of learning ui layout

 By morning finished installing android studio tutorial

Afternoon learned knowledge to learn three ui layout

    I: Use XML UI interface layout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
 <EditText android:id="@+id/edit_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />
 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send" />.layoutthe setContentView (R & ltII: Java code layout UI interface to write
</ LinearLayout>

.activity_main);

FrameLayout frameLayout = new FrameLayout (this) ; // create a frame layout manager
frameLayout.setBackground (this.getResources () getDrawable (R.drawable.ic_launcher ).); // set the background
setContentView (frameLayout); // disposed Activity frameLayout displayed

The TextView text1 = new new the TextView (the this);
text1.setText ( "control code in JAVA UI interface"); // set the display text
text1.setTextSize (TypedValue.COMPLEX_UNIT_PX, 20); // set the text size in pixels
text1 .setTextColor (Color.rgb (100, 100, 100)); // set the color of the text
frameLayout.addView (text1); // add to the layout manager text1

Text2 = new new the TextView the TextView (the this);
text2.setText ( "Program Loading ......"); // set the display text
text2.setTextSize (TypedValue.COMPLEX_UNIT_PX, 20); // set the text size in pixels
// set the color of the text; text2.setTextColor (the method Color.rgb (200 is, 200 is, 100))
LayoutParams for the params = new new LayoutParams for (
ViewGroup.LayoutParams.WRAP_CONTENT,
save the layout parameters // Create; ViewGroup.LayoutParams.WRAP_CONTENT) Object
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL; // set the play display
text2.setLayoutParams (params); // set the layout parameters
frameLayout.addView (text2);
 three: the use of XML and Java code mixed layout UI interface.

    XML achieve quick and easy, but the lack of flexibility, Java flexible, but the development process cumbersome. It can be used to mix XML and Java interface layout. The small change in behavior on the relatively fixed component in XML, the more varied, more complex behavior control components using Java code.

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

</LinearLayout>

public class MainActivity extends Activity {
private ImageView iView[] = new ImageView[2];
private int ImageID[] = new int[] { R.drawable.img01, R.drawable.img02 };


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout layout = (LinearLayout) findViewById(R.id.ll);
LayoutParams params = new LayoutParams(255, 148);
for (int i = 0; i < ImageID.length; i++) {
iView[i] = new ImageView(this);
iView[i].setImageResource(ImageID[i]);
iView[i].setPadding(5, 5, 4, 5);
iView[i].setLayoutParams(params);
layout.addView(iView[i]);
}

}


public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.main, menu);
return true;
}

 



Guess you like

Origin www.cnblogs.com/kongfanbing/p/12274429.html