当前位置:网站首页>Layout use case

Layout use case

2022-06-24 01:57:00 ╱℡&▓

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

// Completely through code , To implement the interface 
public class LayoutOne extends Activity {
    private LinearLayout nameContainer = null;
    private LinearLayout addressContainer = null;
    private LinearLayout parentContainer = null;

    //  Rewriting methods 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        createNameContainer();
        createAddressContainer();
        createParentContainer();
        setContentView(parentContainer);
    }

    //  establish nameContainer
    @SuppressLint("NewApi")
    private void createNameContainer() {
        nameContainer = new LinearLayout(this);
        // layout With layout function , For example, set horizontal row 、 Vertical row , Can contain View, It can also include taking his place layout, So it is also a container 
        //  stay Android I am learning , We use fill_parent, Include xml Use in fill_parent, stay API Level 8(Android
        // 2.2) after , Change it to match_parent
        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        nameContainer.setLayoutParams(layoutParams);
        nameContainer.setOrientation(LinearLayout.HORIZONTAL);
        //  Set up the interior View
        TextView txtView = new TextView(this);
        txtView.setText(" full name :");
        TextView valueView = new TextView(this);
        valueView.setText(" Zhang San ");

        nameContainer.addView(txtView);
        nameContainer.addView(valueView);
    }

    //  establish addressContainer
    @SuppressLint("NewApi")
    private void createAddressContainer() {
        addressContainer = new LinearLayout(this);
        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        addressContainer.setLayoutParams(layoutParams);
        addressContainer.setOrientation(LinearLayout.VERTICAL);

        TextView nameTextView = new TextView(this);
        nameTextView.setText(" Detailed address :");
        TextView valueTextView = new TextView(this);
        valueTextView.setText(" Chemical fiber long way --- Dingjiazhuang ");

        addressContainer.addView(nameTextView);
        addressContainer.addView(valueTextView);
    }

    //  establish rootView, And the first two container be similar , Different things addView It's not about joining the common view, But join layout
    @SuppressLint("NewApi")
    private void createParentContainer() {
        parentContainer = new LinearLayout(this);
        LayoutParams lParams = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        parentContainer.setLayoutParams(lParams);
        parentContainer.setOrientation(LinearLayout.VERTICAL);

        parentContainer.addView(nameContainer);
        parentContainer.addView(addressContainer);
    }
}

原网站

版权声明
本文为[╱℡&▓]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211653475292.html