मैं एंड्रॉइड के लिए नया हूँ। मुझे जहां भी चाहें ड्राइंग ऑब्जेक्ट्स की मुफ्त रेंज पसंद है। तो मैं पूर्ण लेआउट का उपयोग कर रहा हूँ। मुझे एक अलग लेआउट का उपयोग करने के लिए एक संदेश मिलता है। और मैंने पढ़ा है कि यह विभिन्न फोन के विभिन्न res के कारण है। मेरा सवाल यह है कि, पूर्ण लेआउट का उपयोग न करने का यह एकमात्र कारण है? मैंने एक विधि बनाई है जो पिक्सल को समायोजित करने के लिए मीट्रिक का उपयोग करती है।एंड्रॉइड: AbsoluteLayout?
public int widthRatio(double ratioIn){
DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
getWindowManager().getDefaultDisplay().getMetrics(dm);
double screenWidth = dm.widthPixels; //gets screen height
double ratio = screenWidth/100; //gets the ratio in terms of %
int displayWidth = (int)(ratio*ratioIn); //multiplies ratio desired % of screen
return displayWidth;
}
//method to get height or Ypos that is a one size fits all
public int heightRatio(double ratioIn){
DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
getWindowManager().getDefaultDisplay().getMetrics(dm);
double screenHeight = dm.heightPixels; //gets screen height
double ratio = screenHeight/100; //gets the ratio in terms of %
int newHeight = (int)(ratio*ratioIn); //multiplies ratio by desired % of screen
return newHeight;
}
//sets size of any view (button, text, ...) to a one size fits all screens
public void setSizeByRatio(View object, int width, int height){
LayoutParams params = object.getLayoutParams();
params.width = widthRatio(width);
params.height = heightRatio(height);
}
तो अगर मैं setSizeByRatio (बटन, 10, 25) कहता हूं; यह स्क्रीन की चौड़ाई के बटन चौड़ाई को 10% तक सेट करेगा और स्क्रीन की ऊंचाई 25% तक होगी।
क्या कोई फोन है जो निरपेक्ष लेआउट काम नहीं करते हैं? क्या यह लेआउट किसी अन्य मुद्दे का कारण बनता है?
जारी रखें ... और उस पर अनुभव करें और यदि कोई समस्या है तो हमें बताएं ... –
फ़्रेमलाउट एक और विकल्प है http://mobile.tutsplus.com/tutorials/android/android-sdk_frame-layout/ –