采用注釋填充Android布局:Michelangelo

jopen 10年前發布 | 14K 次閱讀 Android開發 移動開發 Michelangelo

Michelangelo是一個布局填充(Inflating)Android庫。它使用注釋處理寫你不想寫的布局代碼并簡化您的視圖組合生成。

一個使用示例:

@InflateLayout(R.layout.custom_view)
public class MyCustomView extends FrameLayout {

    public MyCustomView(Context context) {
        super(context);
    }

    @AfterInflate
    public void updateTextView() {
        ((TextView) findViewById(R.id.my_text_view)).setText("hey!");
    }
}

R.layout.custom_view:

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

    <TextView
            android:id="@+id/my_text_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</merge>

Inflating that View is pretty straightforward:

MyCustomView view = Michelangelo.build(this, MyCustomView.class); 

項目主頁:http://www.baiduhome.net/lib/view/home/1392017978848

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!