मैं अभी भी एक एंड्रॉइड नोब का थोड़ा सा हूं, अगर यह आसान है तो मुझे माफ़ कर दो और मैं इसे देख नहीं रहा हूं।एंड्रॉइड टेक्स्ट लेआउट प्रश्न: दो लेआउटव्यू, साइड-बाय-साइड, विभिन्न लेआउट संरेखण और वजन
एक दृश्य में टेक्स्ट के दो भाग हैं जो पूरी चौड़ाई क्षैतिज रूप से फैलाते हैं, लेकिन टेक्स्ट की एक पंक्ति जितनी अधिक होती है। बाईं तरफ हमेशा पूर्ण रूप से प्रदर्शित होना चाहिए, लेकिन इसकी आवश्यकता से अधिक क्षैतिज स्थान नहीं लेना चाहिए। दाईं तरफ बाईं ओर धक्का दिया जाना चाहिए और स्क्रीन चौड़ाई के बाकी को भरना चाहिए। यदि दाहिने तरफ पाठ इस चौड़ाई से छोटा है, तो पाठ क्षैतिज रूप से दाएं-गठबंधन होना चाहिए। यदि पाठ चौड़ाई से बड़ा है, तो इसे क्षैतिज स्क्रॉल करना चाहिए।
दाईं तरफ के पाठ को अक्सर अपडेट किया जाएगा और ऐप को बताए जाने पर नए टेक्स्ट के साथ स्लाइड करना चाहिए (लेआउट में टेक्स्टस्विचर समझाएं)।
मैंने दो अलग-अलग लेआउट शैलियों का प्रयास किया है। दोनों परिस्थितियों में, मैं बाईं तरफ लेआउट को "धक्का" करने के लिए ले जा सकता हूं, स्क्रॉल करने के लिए दाहिने तरफ, लेकिन मैं यह नहीं समझ सकता कि दाएं किनारे पर दाएं किनारे को कैसे प्राप्त किया जाए। यह हमेशा गठबंधन छोड़ दिया जाता है। यहाँ एक चित्र दिखा क्या हो रहा है ...
http://img10.imageshack.us/img10/5599/androidlayout.png
इसके अलावा (लेकिन कम महत्वपूर्ण), मेरे लेआउट कोड में मैं एंड्रॉयड है:, fadingEdge = TextViews पर "कोई नहीं" लेकिन यह अभी भी एक है स्क्रॉल करते समय बाएं और दाएं तरफ फीका किनारा। ऐसा क्यों है?
यहां मेरे द्वारा बनाए गए दो लेआउट हैं, जो परिणाम दिखाते हैं, लेकिन नतीजे मुझे नहीं चाहिए।
एक क्षैतिज LinearLayout का उपयोग करना ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayoutStatusBar"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2px"
android:background="#555555"
>
<TextView
android:id="@+id/TextViewTimer"
android:textSize="18px"
android:textColor="#FFFFFF"
android:layout_gravity="left"
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0px"
android:layout_marginRight="3px"
android:text="Left Side"
>
</TextView>
<TextSwitcher
android:id="@+id/TextSwitcherDetails"
android:inAnimation="@anim/push_up_in"
android:outAnimation="@anim/push_up_out"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="3px"
android:layout_marginRight="0px"
>
<TextView
android:id="@+id/TextViewDetails1"
android:textSize="18px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadingEdge="none"
android:text="Right Side 1"
>
</TextView>
<TextView
android:id="@+id/TextViewDetails2"
android:textSize="18px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadingEdge="none"
android:text="Right Side 2 - This is a really long text this is long and fun and fun and long"
>
</TextView>
</TextSwitcher>
</LinearLayout>
तो मैं सही-संरेखण के लिए सही पक्ष पर है कि पाठ कैसे मिलता है। धन्यवाद!
संपादित करें:
मैं इस समस्या पाया ... कुछ चीजें गलत थे। सबसे पहले, मैंने गुरुत्वाकर्षण और लेआउट_ग्रैविटी के बीच का अंतर खोजा। मुझे पाठ को सही संरेखित करने के लिए गुरुत्वाकर्षण का उपयोग करने की आवश्यकता थी।
मैं किसी भी अधिक लिंक नहीं जोड़ सकते, तो कॉपी और नीचे
thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/ लिंक पेस्ट
हालांकि, मुझे वास्तव में वह लेआउट नहीं मिला जो मुझे चाहिए था, क्योंकि स्क्रॉलिंग से पहले टेक्स्ट की लंबी लाइनों को सही-गठबंधन किया जाएगा और संदेश के आगे के भाग को तब तक पढ़ा नहीं जा सकता जब तक कि यह चारों ओर लूप्स न हो जाए। मुझे जो करने की ज़रूरत थी वह विचारों के तीन "कॉलम" का उपयोग करती थी, जिसमें मध्यम (खाली) दृश्य "1" होने पर वजन होता था जबकि अन्य "0" होते थे ताकि यह यथासंभव सही पाठ को धक्का दे सके ठीक है, जबकि अभी भी बाएं संरेखण बनाए रखा है।
अगला, मैंने पाया कि टेक्स्टस्विचर की चौड़ाई सबसे बड़ा बच्चा टेक्स्ट व्यू जैसा ही है। यह एक समस्या है जब लंबी लाइन से setText() का उपयोग करके एक छोटी रेखा से स्विच करना क्योंकि मध्यम कॉलम छोटे टेक्स्ट को किनारे पर नहीं दबाएगा। समाधान दो setText() एस का उपयोग करना है। फीड-आउट एनीमेशन का कारण बनने के लिए, फिर एनीमेशन के बाद नई लाइन की फीड-इन एनीमेशन का कारण बनने के लिए एनीमेशन के बाद दौड़ने के लिए एक रननेबल को दबाएं।
अब मेरी एकमात्र समस्या यह है कि जब फीड-आउट एनीमेशन टेक्स्ट की लंबी लाइन पर चलता है, यदि यह मध्य-स्क्रॉल में है, तो यह लुप्त होने से पहले एक्स = 0 स्थिति में रीसेट हो जाता है, इसलिए प्रभाव यह है कि स्क्रॉल, मूल स्थिति पर कूदता है, फिर बाहर निकलता है। किसी को पता है कि इसे कैसे ठीक किया जाए?
(मैं RelativeLayout कोड निकाल ऊपर के बाद से है कि, गलत था के बाद से इस पोस्ट वास्तव में लंबा है।)
यहाँ काम कर रहे लेआउट कोड है ...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayoutStatusBar"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2px"
android:background="#333333"
>
<TextView
android:id="@+id/TextViewTimer"
android:textSize="18px"
android:textColor="#FFFFFF"
android:layout_gravity="top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginLeft="1px"
android:layout_marginRight="4px"
android:text="Left Side"
>
</TextView>
<View
android:id="@+id/ViewSpacer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
></View>
<TextSwitcher
android:id="@+id/TextSwitcherDetails"
android:inAnimation="@anim/push_up_in"
android:outAnimation="@anim/push_up_out"
android:layout_gravity="top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginRight="1px"
>
<TextView
android:id="@+id/TextViewDetails1"
android:textSize="18px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadingEdge="none"
>
</TextView>
<TextView
android:id="@+id/TextViewDetails2"
android:textSize="18px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadingEdge="none"
>
</TextView>
</TextSwitcher>
</LinearLayout>
मुझे लेआउट के दाएं भाग के बारे में एक दृश्य कैसे रखा जाए, इस बारे में मुझे एक ही समस्या थी। तीन "कॉलम" को लागू करने का आपका सुझाव स्पॉट-ऑन था! –