1
我能夠覆蓋表格佈局中的圖像,但設計將以多種尺寸的屏幕運行。因爲我使用margin來達到疊加的效果。以下是代碼。有什麼建議可以達到預期的效果嗎?謝謝。Android如何正確覆蓋圖像,以支持多個屏幕
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="0.7"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="@drawable/ads_body"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.10"
android:gravity="center"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="260dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="50dp">
</View>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0.20"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/scoreboard_avatar_how_to_earn_point"
android:textColor="@color/dark_grey"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="0.20"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/scoreboard_avatar_how_to_earn_point"
android:textColor="@color/dark_grey" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="0.5"
android:background="@drawable/ads_table_border"
android:paddingTop="5dp">
<ImageView
android:id="@+id/scoreboard_point"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:src="@drawable/scoreboard_point" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="@drawable/ads_table_border"
android:paddingTop="5dp">
<TextView
android:id="@+id/ads_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/scoreboard_point"
android:textColor="@color/dark_grey"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="@drawable/ads_table_border"
android:paddingTop="5dp">
<ImageView
android:id="@+id/scoreboard_coin"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:src="@drawable/dibs_scoreboard_coin" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.5"
android:background="@drawable/ads_table_border"
android:paddingTop="5dp">
<TextView
android:id="@+id/ads_coin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="@string/scoreboard_coin"
android:textColor="@color/dark_grey"
android:textStyle="bold" />
</RelativeLayout>
</TableRow>
</TableLayout>
</RelativeLayout>
</FrameLayout>
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginTop="-150dp"
android:adjustViewBounds="true"
android:background="@drawable/head_female_1_circle"
android:scaleType="fitCenter" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp">
<ImageView
android:id="@+id/ifc_reward"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:background="@drawable/hero_chamber_city_line"
android:contentDescription="@string/app_name" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="@+id/btnView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:background="@drawable/ads_button" />
</LinearLayout>
這是創建佈局的有效方法嗎?因爲據我所知,如果我想修改設計,我需要編輯所有的XML。 – cj7 2015-02-24 09:37:25
根據我的經驗,這是最好的方法。 – 2015-02-24 23:26:55