亚洲城地址

亚洲城地址官方网站下载安装

新闻发布日期:2018-4-25

使用“完成膨胀”对合并布局进行膨胀

我有一个观点被用作清单要素,因此我正在努力实现最佳通货膨胀业绩。

在onfinisheview( )中,ImageView和TextView被分配了它们的内容(一个可绘制的和一个字符串),尽管这看起来像是如预期的那样工作,但我不确定是否有更好的方法来执行此操作(似乎onLayout更合适)?

按钮栏标签按钮添加新的.axml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

<?xml version="1.0" encoding="utf-8"?>

<!--LinearLayout-->

<view class="us.sam.views.ButtonBar$LabeledButton"

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/ButtonBar_LabeledButton_AddNew"

style="@style/ButtonBar_LabeledButton"

button_imageview_src="@drawable/v__ic_add_circle_outline_black_24dp"

label_textview_text="@string/ButtonBar_LabeledButton_LabelTextView_Text_AddNew">

<include layout="@layout/ButtonBar_LabeledButton_merge"/>

</view>

按钮栏标签按钮合并

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

<?xml version="1.0" encoding="utf-8"?>

<merge xmlns:android="http://schemas.android.com/apk/res/android">

<!--<view class="us.sam.views.ButtonBar$LabeledButton$Button"-->

<ImageView

android:id="@+id/ButtonBar_LabeledButton_ButtonImageView"

style="@style/ButtonBar_LabeledButton_ButtonImageView"/>

<!--android:src="@drawable/v__ic_add_circle_outline_black_24dp"-->

<!--view class="us.sam.views.ButtonBar$LabeledButton$Label"-->

<TextView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/ButtonBar_LabeledButton_LabelTextView"

style="@style/ButtonBar_LabeledButton_LabelTextView"/>

<!--android:text="Add New"-->

</merge>

标签按钮

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

public class LabeledButton : LinearLayout

{

private ImageView _buttonIV;

private TextView _labelTV;

private int _buttonIV_src;

private string _labelTV_text;

public LabeledButton(Context context, IAttributeSet attributes) : base(context, attributes)

{

ReadAttributes(context, attributes);

}

private void ReadAttributes(Context context, IAttributeSet attributes)

{

Android.Content.Res.TypedArray typedArray = context.ObtainStyledAttributes(attributes, Resource.Styleable.LabeledButton);

_buttonIV_src = typedArray.GetResourceId(Resource.Styleable.LabeledButton_button_imageview_src, 0);

_labelTV_text = typedArray.GetString(Resource.Styleable.LabeledButton_label_textview_text);

typedArray.Recycle();

}

protected override void OnFinishInflate()

{

base.OnFinishInflate();

_buttonIV = FindViewById<ImageView>(Resource.Id.ButtonBar_LabeledButton_ButtonImageView);

_labelTV = FindViewById<TextView>(Resource.Id.ButtonBar_LabeledButton_LabelTextView);

_buttonIV.SetImageResource(_buttonIV_src);

_labelTV.Text = _labelTV_text;

}

}