android 线性布局LinearLayout实例代码

时间:2023-02-23 19:30:13 

布局文件:res/layout/activity_my.xml


[html]  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    tools:context=".MyActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/wo"
        android:textColorHint="@color/calamus" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/shi" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/hao"
        android:textColor="@color/calamus" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/ren" />

</LinearLayout>

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/wo"
        android:textColorHint="@color/calamus" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/shi" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/hao"
        android:textColor="@color/calamus" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/ren" />

</LinearLayout>

资源文件:res/values/strings.xml


[html] view plaincopyprint?<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Linear</string>
    <string name="action_settings">Settings</string>
    <string name="wo">我</string>
    <string name="shi">是</string>
    <string name="hao">好</string>
    <string name="ren">人</string>

</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Linear</string>
    <string name="action_settings">Settings</string>
    <string name="wo">我</string>
    <string name="shi">是</string>
    <string name="hao">好</string>
    <string name="ren">人</string>

</resources>

资源文件:res/values/styles.xml


[html] view plaincopyprint?<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    <color name="calamus">#c77eb5</color>

</resources>

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    <color name="calamus">#c77eb5</color>

</resources>

资源索引文件R.java


[java] view plaincopyprint?/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.eirc.linear;

public final class R {
    public static final class attr {
    }
    public static final class color {
        public static final int calamus=0x7f070000;
    }
    public static final class dimen {
        /**  Default screen margins, per the Android Design guidelines.

         Customize dimensions originally defined in res/values/dimens.xml (such as
         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.

         */
        public static final int activity_horizontal_margin=0x7f040000;
        public static final int activity_vertical_margin=0x7f040001;
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int LinearLayout=0x7f090000;
        public static final int action_settings=0x7f090005;
        public static final int button1=0x7f090001;
        public static final int button2=0x7f090002;
        public static final int button3=0x7f090003;
        public static final int button4=0x7f090004;
    }
    public static final class layout {
        public static final int activity_my=0x7f030000;
    }
    public static final class menu {
        public static final int my=0x7f080000;
    }
    public static final class string {
        public static final int action_settings=0x7f050001;
        public static final int app_name=0x7f050000;
        public static final int hao=0x7f050004;
        public static final int ren=0x7f050005;
        public static final int shi=0x7f050003;
        public static final int wo=0x7f050002;
    }
    public static final class style {
        /**
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

 
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

 
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.

 API 11 theme customizations can go here.

        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.

 API 14 theme customizations can go here.
         */
        public static final int AppBaseTheme=0x7f060000;
        /**  Application theme.
 All customizations that are NOT specific to a particular API-level can go here.
         */
        public static final int AppTheme=0x7f060001;
    }
}

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.eirc.linear;


public final class R {
    public static final class attr {
    }
    public static final class color {
        public static final int calamus=0x7f070000;
    }
    public static final class dimen {
        /**  Default screen margins, per the Android Design guidelines.

         Customize dimensions originally defined in res/values/dimens.xml (such as
         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.

         */
        public static final int activity_horizontal_margin=0x7f040000;
        public static final int activity_vertical_margin=0x7f040001;
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int LinearLayout=0x7f090000;
        public static final int action_settings=0x7f090005;
        public static final int button1=0x7f090001;
        public static final int button2=0x7f090002;
        public static final int button3=0x7f090003;
        public static final int button4=0x7f090004;
    }
    public static final class layout {
        public static final int activity_my=0x7f030000;
    }
    public static final class menu {
        public static final int my=0x7f080000;
    }
    public static final class string {
        public static final int action_settings=0x7f050001;
        public static final int app_name=0x7f050000;
        public static final int hao=0x7f050004;
        public static final int ren=0x7f050005;
        public static final int shi=0x7f050003;
        public static final int wo=0x7f050002;
    }
    public static final class style {
        /**
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
  

            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
      

        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.

 API 11 theme customizations can go here.

        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.

 API 14 theme customizations can go here.
         */
        public static final int AppBaseTheme=0x7f060000;
        /**  Application theme.
 All customizations that are NOT specific to a particular API-level can go here.
         */
        public static final int AppTheme=0x7f060001;
    }
}

Activity:


[java] view plaincopyprint?package com.eirc.linear;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
    }

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

}


package com.eirc.linear;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MyActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_my);
 }

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

}

最终效果:

android 线性布局LinearLayout实例代码

标签:线性布局,LinearLayout
0
投稿

猜你喜欢

  • SpringBoot分离打Jar包的两种配置方式

    2023-01-30 09:06:59
  • 基于Elasticsearch5.4的常见问题总结

    2022-07-15 15:02:49
  • 在SpringBoot项目中的使用Swagger的方法示例

    2022-01-04 15:14:39
  • Spring集成Druid连接池及监控配置的全过程

    2023-08-25 05:22:20
  • Spring Boot 自动配置的实现

    2023-07-21 18:18:55
  • Java的后台文件夹下文件的遍历完整代码

    2023-09-18 12:32:19
  • mybatis中insert主键ID获取和多参数传递的示例代码

    2023-09-20 07:11:00
  • 基于Java swing组件实现简易计算器

    2023-03-29 02:10:07
  • java使用异或实现变量互换和异或加密解密示例

    2023-10-19 16:53:38
  • spring boot微服务场景下apollo加载过程解析

    2022-05-20 13:55:32
  • android 设置全屏的两种方法

    2023-06-30 00:06:11
  • SpringBoot中使用Servlet三大组件的方法(Servlet、Filter、Listener)

    2021-07-19 18:41:43
  • java ThreadPool线程池的使用,线程池工具类用法说明

    2023-06-23 18:12:12
  • Kotlin与Java相互调用的完整实例

    2023-06-17 03:23:23
  • C#多线程学习之(二)操纵一个线程的方法

    2022-02-27 08:53:27
  • C#实现绘制浮雕图片效果实例

    2023-10-10 04:34:04
  • C#对象为Null模式(Null Object Pattern)实例教程

    2023-07-27 15:53:28
  • Java微信公众平台之获取地理位置

    2021-05-28 19:36:40
  • Java中new关键字和newInstance方法的区别分享

    2022-12-04 03:12:52
  • 深入理解TextView实现Rich Text--在同一个TextView设置不同字体风格

    2023-05-25 04:52:01
  • asp之家 软件编程 m.aspxhome.com