首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

Eclipse/Android 顯示 UI 設計圖並實現區域點擊跳轉

     編輯:程式設計疑難解答

基本步驟

  1. 將設計圖切片,放入 res/drawable-xxx/ 對應密度目錄
  2. 佈局文件用 ImageView 或 FrameLayout 背景顯示整圖
  3. 在圖片上方疊加透明 View(或自定義 View),按設計圖座標設置點擊區域

代碼示例

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/ui_design" />
    <View
        android:id="@+id/btn_funny"
        android:layout_width="120dp"
        android:layout_height="60dp"
        android:layout_marginLeft="80dp"
        android:layout_marginTop="200dp"
        android:background="@android:color/transparent" />
</FrameLayout>
findViewById(R.id.btn_funny).setOnClickListener(v -> {
    startActivity(new Intent(this, FunnyActivity.class));
});

進階方案

複雜交互建議用 WebView 加載 HTML imagemap,或採用 ConstraintLayout + Guideline 精確定位。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved