hjr-Android:关于UI

View

绘制View,继承View并重写几个方法,可以自己在style.xml文件夹中定义属性,在自定义View中使用。自定义的view与布局文件没有关系,在自定义View中修改,布局文件中不会一起修改,如果显示的是布局文件就不会有变化。

LayoutParams 一般指,大小、位置、内外边距,在addView时一般要设置一下,不设置默认使用父类的,也可以自己重新设置。

想要在activity中控制自定义的View,可以在自定义View中,建一个方法供activity调用,其中最重要的是该方法中要有这一句postInvalidate();,这样每次执行改方法都会重新调用onDraw。而我们可以在这个方法里根据调用时传入的参数改变自定义View里的一些值,这样在重新执行onDrow后,自定义View就会做相应改变。

Layout

XML布局文件,里面可以直接用<包名+类名/>引入自定义View,也可以include 其他的布局文件,对include布局内的控件操作时不能直接获取,需要两步。

  1. View view = this.findViewById(R.id.include_id);//根据include id获取View
  2. view_button = (Button) view.findViewById(R.id.button1); //根据include view中的id获取其中的控件

inflate 三种方式:

    LayoutInflater inflater = LayoutInflater.from(this); 

 LayoutInflater inflater = getLayoutInflater();
 
LayoutInflater inflater =(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);

一般一个activity对应一个布局,如果要用其他的布局文件中的控件,可以用inflate 找 到xml布局文件xxx,再用 xxx.findViewById找到控件。

例如,findViewById获取为null可以试试在前面加上layout的view

LayoutInflater inf = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inf.inflate(R.layout.xxx, null);
MyView myView = (MyView)view.findViewById(R.id.xxx);

adapter

这个用来连接视图与数据,视图一般指ListView、GridView这种包含很多子视图的视图,一般要传入,this、子视图xml文件、和数据,数据一般是List,有数组、数据库……形式,可以在每个子视图中添加事件,不过一般都是通过传入的标识控制,不是一个个的进行事件控制。
ViewHolder里面可以存储子View中的控件

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个简单的 HTML 代码示例,可以用来制作类似于 iPhone 的网页: ```html <!DOCTYPE html> <html> <head> <title>iPhone 网页示例</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { background-color: #f2f2f2; font-family: Arial, Helvetica, sans-serif; } .container { margin: 20px auto; max-width: 400px; background-color: #fff; border-radius: 10px; padding: 20px; box-shadow: 0px 0px 10px rgba(0,0,0,0.2); } .header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; } .header img { height: 30px; } .navbar { display: flex; background-color: #eee; border-radius: 5px; overflow: hidden; margin-bottom: 20px; } .navbar a { display: block; padding: 10px; text-align: center; flex: 1; text-decoration: none; color: #555; font-weight: bold; } .navbar a.active { background-color: #007aff; color: #fff; } .content { text-align: center; margin-bottom: 20px; } .content img { max-width: 100%; height: auto; margin-bottom: 10px; } .footer { text-align: center; font-size: 12px; color: #aaa; } </style> </head> <body> <div class="container"> <div class="header"> <img src="https://i.imgur.com/6f8yvRP.png" alt="iPhone" /> <button>搜索</button> </div> <div class="navbar"> <a href="#" class="active">主页</a> <a href="#">新闻</a> <a href="#">社交</a> <a href="#">设置</a> </div> <div class="content"> <img src="https://i.imgur.com/4a74HJr.jpg" alt="iPhone" /> <h2>欢迎来到 iPhone 网页示例</h2> <p>这是一个简单的 HTML 示例,用于展示如何制作类似于 iPhone 的网页。</p> </div> <div class="footer"> <p>©2021 iPhone 网页示例</p> </div> </div> </body> </html> ``` 在浏览器中打开该 HTML 文件,即可看到类似于 iPhone 的网页效果。可以根据需要进行修改和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

架构师小侯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值