osm android标记在不同屏幕上太小

时间:2018-12-14 21:04:30

标签: android osmdroid

我正在使用OSM android开发一个android应用。 问题:在两部LG手机上测试代码,我看到两种不同尺寸的自定义标记。 问题:谁能向我解释这些设备下这些标记的大小为何不同,以及如何修复以下代码。我还添加了来自LG-K428和LG-D851这两种设备的图像。 LG-D851 LG-K428

public Bitmap createCustomMarker(int no,int  vote, View view , String image) {

    View marker = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker, null);

    relativeLayout1 = marker.findViewById(R.id.view_user_avater);
    relativeLayout2 = marker.findViewById(R.id.view_hash);
    relativeLayout3 = marker.findViewById(R.id.view_trash);

    User mUser = SharedPref.readObject("user", User.class);

    switch (no) {
        case 2:
            relativeLayout3.setVisibility(View.VISIBLE);
            relativeLayout1.setVisibility(View.GONE);
            relativeLayout2.setVisibility(View.GONE);
            break;
        case 1:
            relativeLayout2.setVisibility(View.VISIBLE);
            relativeLayout1.setVisibility(View.GONE);
            relativeLayout3.setVisibility(View.GONE);
            break;
        case 3:
            relativeLayout1.setVisibility(View.VISIBLE);
            relativeLayout2.setVisibility(View.GONE);
            relativeLayout3.setVisibility(View.GONE);
            break;
        default:
            break;
    }
TextView tv2=        relativeLayout3.findViewById(R.id.text_badge);

   if(vote!=0){
       tv2.setText(String.valueOf(vote));
   }
   else{
        relativeLayout3.findViewById(R.id.text_badge).setVisibility(View.GONE);
    }

    relativeLayout1.findViewById(R.id.text_badge).setVisibility(View.GONE);
    relativeLayout1.findViewById(R.id.hashImage).setVisibility(View.GONE);
    relativeLayout2.findViewById(R.id.text_badge).setVisibility(View.GONE);
    relativeLayout2.findViewById(R.id.image_avatar).setVisibility(View.GONE);
    relativeLayout3.findViewById(R.id.hashImage).setVisibility(View.GONE);

    DisplayMetrics displayMetrics = new DisplayMetrics();

    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    marker.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
    System.out.println("width="+displayMetrics.widthPixels+ ";"+ "height="+displayMetrics.heightPixels);
    marker.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
    marker.buildDrawingCache();
    Bitmap bitmap = Bitmap.createBitmap(marker.getMeasuredWidth(), marker.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    marker.draw(canvas);
    return bitmap;
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/view_user_avater_layout"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:visibility="visible">

    <include
        android:id="@+id/view_user_avater"
        layout="@layout/custom_marker_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp"
        android:visibility="visible" />

    <include
        android:id="@+id/view_hash"
        layout="@layout/custom_marker_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:visibility="gone" />

    <include
        android:id="@+id/view_trash"
        layout="@layout/custom_marker_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:visibility="gone" />
</RelativeLayout>   

<?xml version="1.0"[enter image description here][1] encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/image_avatar_layout"[enter image description here][1]
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:background="@drawable/ic_hashorstash_allred">

    <ImageView
        android:id="@+id/hashImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        android:visibility="visible"
        app:srcCompat="@drawable/ic_hashorstash" />

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="60dp">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/image_avatar"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:layout_below="@+id/text_badge"
            android:layout_alignParentEnd="true"
            android:layout_marginTop="50dp"
            android:layout_marginEnd="22dp"
            android:contentDescription="@null"
            android:src="@drawable/demoman"
            android:visibility="visible"
            app:civ_border_color="#fff"
            app:civ_border_width="2dp" />
    </TableRow>

    <TextView
        android:id="@+id/text_badge"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="6dp"
        android:layout_marginRight="9dp"
        android:background="@drawable/badge_green"
        android:gravity="center"
        android:paddingLeft="2dp"
        android:paddingRight="2dp"
        android:text="18"
        android:textColor="@android:color/white"
        android:textSize="12sp" />

</RelativeLayout>

0 个答案:

没有答案