有图有真相,例如:
你的XML假如是这样:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_logo" />
<Button
android:id="@+id/version_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_54"
android:textColor="@color/colFFFFFF"
android:textSize="18sp"
android:text="版本:1.0.0"
android:background="@drawable/bg_version_btn" />
<TextView
android:id="@+id/companyname_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@color/transparent"
android:text="@string/companyname"
android:textColor="@color/col8d8d8d"
android:layout_marginBottom="@dimen/font_size_40"
android:textSize="14sp" />
<TextView
android:id="@+id/email_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/dp_22"
android:text="邮箱:bd@che08.com"
android:textColor="@color/colA0A0A0"
/>
</RelativeLayout>
生成代码如下:
// Content View Elements
private ImageView mLogo;
private Button mVersion_btn;
private TextView mCompanyname_tv;
private TextView mEmail_tv;
// End Of Content View Elements
private void bindViews() {
mLogo = (ImageView) findViewById(R.id.logo);
mVersion_btn = (Button) findViewById(R.id.version_btn);
mCompanyname_tv = (TextView) findViewById(R.id.companyname_tv);
mEmail_tv = (TextView) findViewById(R.id.email_tv);
}
Android Layout Binder(在线将XML中View find出来,生成java代码的工具),布布扣,bubuko.com