0

ここから QuickAction コードを使用していますが、特定の画面サイズで正しく表示されないことを 1 週間いじった後、問題が発生しています。問題をコードの 1 行に絞り込みましたが、携帯電話とエミュレーターで同時に正しく表示できないようです。説明させてください。

問題の行は「PopupWindows.java」ファイルにあり、次のとおりです。

 public static final int MAX_WIDTH_POPUP_WINDOWS = 435;

これを「433」に変更しました。これは、解像度が 800x480 の 2.3、4.0.1、および 4.1 エミュレーターの 3 つのアイコンに完全に適合するためです。次のようになります。

ここに画像の説明を入力

しかし、電話 (1920x1080) では、次のようにレンダリングされます。

ここに画像の説明を入力

奇妙なのは、その番号を 865 にすると、電話で正しくレンダリングされることです。

ここに画像の説明を入力

しかし、エミュレータでは次のように表示されます。

ここに画像の説明を入力

Quickaction の xml を変更してコンテンツをラップし、ハードコードされた幅を設定しようとしましたが、これで修正されません。以下のコードを参照してください。

PopupWindows.java

package actionitem;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater; 
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.PopupWindow;

/**
 * Custom popup window.
 * 
 * @author Lorensius W. L. T <lorenz@londatiga.net>
 * 
 */
public class PopupWindows {
protected Context mContext;
protected PopupWindow mWindow;
protected View mRootView;
protected Drawable mBackground = null;
protected WindowManager mWindowManager;
Resources res;
// public static final int MAX_WIDTH_POPUP_WINDOWS = 433;

public static final int MAX_WIDTH_POPUP_WINDOWS = 865;

/**
 * Constructor.
 * 
 * @param context
 *            Context
 */
public PopupWindows(Context context) {
    mContext = context;
    mWindow = new PopupWindow(context);

    mWindow.setTouchInterceptor(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                mWindow.dismiss();

                return true;
            }

            return false;
        }
    });

    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}

/**
 * On dismiss
 */
protected void onDismiss() {
}

/**
 * On show
 */
protected void onShow() {
}

/**
 * On pre show
 */
protected void preShow() {
    if (mRootView == null)
        throw new IllegalStateException("setContentView was not called with a view to display.");

    onShow();

    if (mBackground == null)
        mWindow.setBackgroundDrawable(new BitmapDrawable(res));
    else
        mWindow.setBackgroundDrawable(mBackground);

    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
    int w = screenWidth < MAX_WIDTH_POPUP_WINDOWS ? screenWidth : MAX_WIDTH_POPUP_WINDOWS;
    // if (screenWidth < 490) {
    // w = 433;
    // } else if (screenWidth > 865) {
    // w = 865;
    // }
    mWindow.setWidth(w);// WindowManager.LayoutParams.WRAP_CONTENT);
    mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    mWindow.setTouchable(true);
    mWindow.setFocusable(true);
    mWindow.setOutsideTouchable(true);

    mWindow.setContentView(mRootView);
}

/**
 * Set background drawable.
 * 
 * @param background
 *            Background drawable
 */
public void setBackgroundDrawable(Drawable background) {
    mBackground = background;
}

/**
 * Set content view.
 * 
 * @param root
 *            Root view
 */
public void setContentView(View root) {
    mRootView = root;

    mWindow.setContentView(root);
}

/**
 * Set content view.
 * 
 * @param layoutResID
 *            Resource id
 */
public void setContentView(int layoutResID) {
    LayoutInflater inflator = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    setContentView(inflator.inflate(layoutResID, null));
}

/**
 * Set listener on window dismissed.
 * 
 * @param listener
 */
public void setOnDismissListener(PopupWindow.OnDismissListener listener) {
    mWindow.setOnDismissListener(listener);
}

/**
 * Dismiss the popup window.
 */
public void dismiss() {
    mWindow.dismiss();
}
}

そして私のquickaction.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="220dp"
android:layout_height="wrap_content" >

<FrameLayout
    android:id="@+id/header2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/scroll"
    android:layout_marginTop="10dip"
    android:background="@drawable/quickaction_top_frame" />

<ImageView
    android:id="@+id/arrow_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/quickaction_arrow_up" />

<HorizontalScrollView
    android:id="@+id/scroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/header2"
    android:background="@drawable/quickaction_slider_background"
    android:fadingEdgeLength="0dip"
    android:paddingLeft="1dip"
    android:scrollbars="none" >

    <LinearLayout
        android:id="@+id/tracks"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="4dip"
        android:paddingTop="4dip" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/quickaction_slider_grip_left" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/quickaction_slider_grip_right" />
    </LinearLayout>
</HorizontalScrollView>

<FrameLayout
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignRight="@id/scroll"
    android:layout_below="@id/scroll"
    android:background="@drawable/quickaction_bottom_frame" />

<ImageView
    android:id="@+id/arrow_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/footer"
    android:layout_marginTop="-1dip"
    android:src="@drawable/quickaction_arrow_down" />

</RelativeLayout>

長い投稿で申し訳ありませんが、私はサポートで働いているので、それは習慣であり、事前に詳細を提供することが問題をより早く解決するのに役立つと信じています:)

ありがとう!

4

1 に答える 1