zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Android入门之控件布局初步

Android入门 控件 布局 初步
2023-09-11 14:16:05 时间

布局方法分类:



实例:

1.实现Linear布局


代码清单:

1. MainActivity.java

package com.jk.test;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity {

 @Override

 protected void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

 setContentView(R.layout.first_layout);

 @Override

 public boolean onCreateOptionsMenu(Menu menu) {

 // Inflate the menu; this adds items to the action bar if it is present.

 getMenuInflater().inflate(R.menu.main, menu);

 return true;

2.first_layout.xml

 ?xml version="1.0" encoding="utf-8"? 

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

 android:layout_width="match_parent"

 android:layout_height="match_parent"

 android:orientation="vertical" 

 TextView 

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:background="#ff0000"

 android:text="first"/ 

 TextView 

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:background="#00ff00"

 android:text="second"/ 

 /LinearLayout 



2.first_layout.xml

 ?xml version="1.0" encoding="utf-8"? 

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

 android:layout_width="match_parent"

 android:layout_height="match_parent"

 android:orientation="horizontal" 

 TextView 

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:background="#ff0000"

 android:text="first"/ 

 TextView 

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:background="#00ff00"

 android:text="second"/ 

 /LinearLayout 

相应的使用不同的布局需要修改你的xml文件即可。


Android自定义控件 | 源码里有宝藏之自动换行控件 回想一下在作文本上写作的场景,当从左到右写满一行后,会切换到下一行的开头继续写。如果把“作文本”比作容器控件,把“字”比作子控件。Android 原生控件中没有能“自动换行”的容器控件。
Android控件之ProgressBar ProgressBar位于android.widget包下,其继承于View,主要用于显示一些操作的进度。应用程序可以修改其长度表示当前后台操作的完成情况。因为进度条会移动,所以长时间加载某些资源或者执行某些耗时的操作时,不会使用户界面失去响应。ProgressBar类的使用非常简单,只需将其显示到前台,然后启动一个后台线程定时更改表示进度的数值即可