zoukankan      html  css  js  c++  java
  • ViewStub

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
    
        <ViewStub
            android:id="@+id/viewstub_demo_text"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:layout_marginLeft="5dip"
            android:layout_marginRight="5dip"
            android:layout_marginTop="10dip"
            android:layout="@layout/text"/>
        <ViewStub
            android:id="@+id/viewstub_demo_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dip"
            android:layout_marginRight="5dip"
            android:layout="@layout/image"/>
    
    </LinearLayout>
    <ImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
            android:id="@+id/viewstub_demo_imageview"
          >
    
    </ImageView>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/viewstub_demo_textview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#aa664411"
            android:textSize="16sp"/>
    
    </LinearLayout>
      public class MainActivity extends Activity  {
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
    
                if ((((int) (Math.random() * 100)) & 0x01) == 0) {
                } else {
                }
                    ViewStub stub = (ViewStub) findViewById(R.id.viewstub_demo_text);
                    stub.inflate();
                    TextView text = (TextView) findViewById(R.id.viewstub_demo_textview);
                    text.setText("The tree of liberty must be refreshed from time to time" +
                            " with the blood of patroits and tyrants! Freedom is nothing but " +
                            "a chance to be better!");
    
                    // to show image
                    // all you have to do is inflate the ViewStub for imageview
                    ViewStub stub2 = (ViewStub) findViewById(R.id.viewstub_demo_image);
                    stub2.inflate();
                    ImageView image = (ImageView) findViewById(R.id.viewstub_demo_imageview);
                    image.setImageResource(R.mipmap.ic_launcher);
    
            }
        }
  • 相关阅读:
    vue——项目技术储备
    Framework7—— 混合开发
    CSS——常见的问题
    Vue——常见问题
    Vue——使用 watch 注意项
    Node——微服务架构(二)
    C——基本词汇
    Go——空接口与断言
    Node——PM2
    Vue——组件异步加载与路由懒加载
  • 原文地址:https://www.cnblogs.com/Ocean123123/p/13891573.html
Copyright © 2011-2022 走看看