首页 > 系统 > Android > 正文

《第一行代码--Android》阅读笔记之界面设计

2019-11-15 01:06:18
字体:
来源:转载
供稿:网友
《第一行代码--Android》阅读笔记之界面设计

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

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

  • pxis one pixel.
  • spis scale-independent pixels.
  • dipis Density-independent pixels.(dip == dp is ture)
Here is the differencedpDensity-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/dpispScale-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

  • spfor font sizes
  • dipfor 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与goneinvisible:控件消失,点击事件失效,仍然占据着位置gone:控件消失,布局位置被腾空3.设置进度条Style设置为水平:style="?android:attr/progressBarStyleHorizontal"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,可显示一批Stringprivate String[] data = { "Apple", "Banana", "Orange", "Watermelon","Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango" };@Overrideprotected 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.编写聊天界面方式选择使用一个布局,用于存储来往消息气泡,根据消息流向设置控件可见性这样的方式要优于使用多个布局文件
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表