कोई भी स्क्रीन चौड़ाई समाधान ढूंढता है? - मयूर आर अमिपारा जून 5 '15 पर 10:27
अपने कस्टम व्यू के ऑनर को ओवरराइड करें, इसकी चौड़ाई स्क्रीन चौड़ाई पर सेट करें। और ऑनआउट में, अपने बच्चे के विचारों को रिलायआउट करें।
यह मेरे लिए काम करता है।
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.RelativeLayout;
import com.android.gallery3d.R;
public class SelectActionModeCustomView extends RelativeLayout {
private View mLeftButton;
private View mRightButton;
private int mScreenWidth;
private static final String TAG = "SelectActionView";
public SelectActionModeCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
mScreenWidth = metrics.widthPixels;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mLeftButton = findViewById(R.id.cancel);
mRightButton = findViewById(R.id.select_action);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
this.setMeasuredDimension(mScreenWidth, this.getMeasuredHeight());
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
int childLeft = 0;
int childTop = 0;
childLeft = 0;
childTop = ((b - t) - mLeftButton.getMeasuredHeight())/2;
mLeftButton.layout(childLeft, childTop,
childLeft + mLeftButton.getMeasuredWidth(),
childTop + mLeftButton.getMeasuredHeight());
childLeft = (r - l) - mRightButton.getMeasuredWidth();
childTop = ((b - t) - mRightButton.getMeasuredHeight())/2;
mRightButton.layout(childLeft, childTop,
childLeft + mRightButton.getMeasuredWidth(),
childTop + mRightButton.getMeasuredHeight());
}
}
एक तस्वीर प्रदान करने से आप यह स्पष्ट कर सकते हैं कि आप किस बारे में बात कर रहे हैं। – JoxTraex
IMHO, जो आप चाहते हैं वह अमान्य डिज़ाइन है। परिभाषा के अनुसार, उपयोगकर्ता कार्रवाई मोड को खारिज कर सकता है, जैसे बैक बटन दबाकर। एक क्रिया मोड डिफ़ॉल्ट रूप से विनाशकारी होना चाहिए: एक क्रिया मोड को सक्रिय करना, फिर बैक (या पूर्ण टैप करना) दबाकर उपयोगकर्ता के डेटा में कोई परिवर्तन नहीं होना चाहिए। – CommonsWare
हम्म .. यह भी सच है। तो इसे पाठ बदलने का एक तरीका है ताकि उपयोगकर्ता भ्रमित न हो? कारण कभी-कभी "रद्द करें" "पूर्ण" से बेहतर विवरण है। Ty! –