星空网 > 软件开发 > Java

《第一行代码

1.单位dp、dip、sp、pt、px、in、mm

这里引用StackOverFlow上的一个解答:

  • px is one pixel.
  • sp is scale-independent pixels.
  • dip is Density-independent pixels.( dip == dp is ture)
 
《第一行代码
Here is the difference
《第一行代码
dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
即:dp=160*px/dpi
 
sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
 
Remenber this:

You would use

  • sp for font sizes
  • dip for everything else

To make it absolutely clear - try to never use anything but sp or dp unless you absolutely have to. Using sp/dp will make your Android applications compatible with multiple screen densities and resolutions.
 
2.可见性invisible与gone
invisible:控件消失,点击事件失效,仍然占据着位置
gone:控件消失,布局位置被腾空
 
3.设置进度条Style
设置为水平:
 
4.LinearLayout
想要在某一行设置一个EditText和Button, 让Button宽度包裹内容,让EditText占据屏幕剩余宽度
<EditText
android:id="@+id/input_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Type something"
/>
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
/> 
 
5.一个简易快速ListView,可显示一批String
private String[] data = { "Apple", "Banana", "Orange", "Watermelon",
"Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango" };
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(

MainActivity.this, android.R.layout.simple_list_item_1, data);

ListView listView = (ListView) findViewById(R.id.list_view);

listView.setAdapter(adapter);


 
6.自定义Adapter时候重载getView()方法的作用
这个方法在每个子项被滚动到屏幕内的时候会被调用


 
7.ListView性能优化
使用Adapter中getView()方法的参数convertView,避免每次重复加载布局文件
使用ViewHolder来记录绑定的控件id与控件实例
 
8.编写聊天界面方式选择
使用一个布局,用于存储来往消息气泡,根据消息流向设置控件可见性
这样的方式要优于使用多个布局文件



原标题:《第一行代码

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

德国VAT税号查询指南:https://www.kjdsnews.com/a/1387975.html
德国VAT税号查询完全指南:https://www.kjdsnews.com/a/1387976.html
德国VAT税号查询及申报流程指南:https://www.kjdsnews.com/a/1387977.html
德国VAT税号查询一次性获取最新信息:https://www.kjdsnews.com/a/1387978.html
德国VAT税号位数详细剖析:https://www.kjdsnews.com/a/1387979.html
德国VAT税务证书申请流程及时限:https://www.kjdsnews.com/a/1387980.html
昆明旅游索道公司 昆明旅游索道公司有哪些:https://www.vstour.cn/a/406243.html
太仓美食网(探寻太仓最美味的美食):https://www.vstour.cn/a/406244.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流