zoukankan      html  css  js  c++  java
  • 在代码中写view 的长宽高等

    获得资源的id的另一种方法

    int layoutRes = getResources().getIdentifier("pager_view" + i, "layout", getPackageName());

    这里写图片描述

    假设我们想在这个相对布局中填一个子节点

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/rl"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
    </RelativeLayout>

    这里写图片描述

    package com.example.com.fmyh;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    
    import org.w3c.dom.Text;
    import org.xml.sax.Attributes;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.helpers.XMLReaderFactory;
    import org.xmlpull.v1.XmlPullParserException;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.content.res.XmlResourceParser;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.RelativeLayout;
    import android.widget.RelativeLayout.LayoutParams;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            RelativeLayout rl=(RelativeLayout) findViewById(R.id.rl);
    
            TextView tv = new TextView(this);
    
            tv.setText("你好");
    
            //设置长宽高 这里要选父节点RelativeLayout的包
            LayoutParams lf = new LayoutParams(20,20);
            //设置左右上下的margin值
            lf.setMargins(10, 10, 10, 10);
    
            tv.setLayoutParams(lf);
    
            rl.addView(tv);
        }
    
    
    }
    
  • 相关阅读:
    概率统计(DP)
    iOS中几种定时器
    微信开发笔记——微信网页登录授权,获取用户信息
    swift中通知的使用
    Swift的基础,操作符,字符串和集合类型
    NSNotificationCenter
    IOS中通知中心(NSNotificationCenter)的使用总结
    Swift观察者模式
    swift中通知的使用
    Swift
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152211.html
Copyright © 2011-2022 走看看