Android零碎知识点
程序员文章站
2022-05-10 11:51:29
...
退出程序,可以直接杀死进程:
不再用USB线,直接用adb命令将apk push到sdcard中;
将当前目录下的所有文件push到sdcard中install文件夹。
关于那些烦人的单位:
[size=large][color=blue]res/values/color.xml:[/color][/size]
[color=red]程序异常终止的原因:[/color]
今天在程序中的switch中,忘写了一个break;程序经常莫名其妙的发生异常, 查看log信息也查不出来,后来看代码,才发现了这个漏掉的break~~
android.os.Process.killProcess(android.os.Process.myPid());
不再用USB线,直接用adb命令将apk push到sdcard中;
#:adb push ./ /sdcard/install
将当前目录下的所有文件push到sdcard中install文件夹。
关于那些烦人的单位:
android:maxWidth
Since: API Level
An optional argument to supply a maximum width for this view. See {see android.widget.ImageView#setMaxWidth} for details.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol maxWidth.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="专辑"
android:textSize="20sp"
/>
<ImageButton
android:layout_width="100dip"
android:layout_height="50dip"
android:src="@android:drawable/sym_action_call" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dip"
android:paddingRight="8dip">
<TextView
android:text="@string/table_layout_9_open_shortcut"
android:gravity="right"
[color=red] android:padding="3dip"[/color] />
<Gallery android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
[color=red]android:spacing="16dp"[/color]
/>
Dimension
A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android:
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. The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
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 the user's preference.
pt
Points - 1/72 of an inch based on the physical size of the screen.
px
Pixels - corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.
mm
Millimeters - based on the physical size of the screen.
in
Inches - based on the physical size of the screen.
Note: A dimension is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine dimension resources with other simple resources in the one XML file, under one <resources> element.
file location:
res/values/filename.xml
The filename is arbitrary. The <dimen> element's name will be used as the resource ID.
resource reference:
In Java: R.dimen.dimension_name
In XML: @[package:]dimen/dimension_name
syntax:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen
name="dimension_name"
>dimension</dimen>
</resources>elements:
<resources>
Required. This must be the root node.
No attributes.
<dimen>
A dimension, represented by a float, followed by a unit of measurement (dp, sp, pt, px, mm, in), as described above.
attributes:
name
String. A name for the dimension. This will be used as the resource ID.
example:
XML file saved at res/values/dimens.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textview_height">25dp</dimen>
<dimen name="textview_width">150dp</dimen>
<dimen name="ball_radius">30dp</dimen>
<dimen name="font_size">16sp</dimen>
</resources>This application code retrieves a dimension:
Resources res = getResources();
float fontSize = res.getDimension(R.dimen.font_size);This layout XML applies dimensions to attributes:
<TextView
android:layout_height="@dimen/textview_height"
android:layout_width="@dimen/textview_width"
android:textSize="@dimen/sixteen_sp"/>
[size=large][color=blue]res/values/color.xml:[/color][/size]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="red">#7f00</drawable>
<drawable name="blue">#770000ff</drawable>
<drawable name="green">#7700ff00</drawable>
<drawable name="yellow">#77ffff00</drawable>
<drawable name="screen_background_black">#ff000000</drawable>
<drawable name="translucent_background">#e0000000</drawable>
<drawable name="transparent_background">#00000000</drawable>
<color name="solid_red">#f00</color>
<color name="solid_blue">#0000ff</color>
</resources>
[color=red]程序异常终止的原因:[/color]
今天在程序中的switch中,忘写了一个break;程序经常莫名其妙的发生异常, 查看log信息也查不出来,后来看代码,才发现了这个漏掉的break~~
上一篇: 【模板】归并排序求逆序对
下一篇: 前端零碎知识点(二)