2012-09-04 18 views
24

में ImageView के साथ छवि दोहराएं RelativeLayout में ImageView के साथ छवि को दोहराना चाहता हूं। क्या बिटमैप एक्सएमएल का उपयोग करना संभव है और RelativeLayout के साथ टाइलमोड "repeat" का उपयोग करना संभव हो सकता है, क्योंकि मैंने इंटरनेट पर चीजों को देखा है, वे सभी LinearLayout से संबंधित हैं।RelativeLayout

किसी भी मदद या टिप का गर्मजोशी से स्वागत किया जाएगा।

उत्तर

62

एक एक्सएमएल पृष्ठभूमि नामित फ़ाइल बनाएँ Drawable फ़ोल्डर

background.xml

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
android:src="@drawable/imagename" 
android:tileMode="repeat" /> 

में अपने रिश्तेदार लेआउट में पृष्ठभूमि के रूप में ऊपर एक्सएमएल जोड़ने

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/background" /> 
+6

एंड्रॉयड की स्थापना के रूप में बिटमैप हैं: scaleType = "fitXY" neccesary है यदि आप इसे ImageView में डालते हैं। –

3

हां, यह संभव है। XML में android:tileMode="repeat" के साथ Drawable (bitmap) के रूप में अपनी दोहराने वाली छवि को परिभाषित करें और इसे अपने RelativeLayout की पृष्ठभूमि के रूप में उपयोग करें।

10

पाठ्यक्रम का हां, आप इसे सापेक्ष लेआउट के साथ उपयोग कर सकते हैं। इसे अपने रिलेवेटिवआउट की पृष्ठभूमि के रूप में उपयोग करें। मैंने इसे अपने प्रोजेक्ट में भी इस्तेमाल किया।

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:background="@drawable/top_header_bg_repeat" 
     android:gravity="center"> 

top_header_bg_repeat.xml (in drawable folder) 
---------------------------------------------- 

<bitmap 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/top_header" 
    android:tileMode="repeat" 
    android:dither="true"/> 

Set Bitmap in ImageView 
---------------------- 

<ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/top_header_bg_repeat" 
     android:scaleType="fitXY"/> 

<ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/top_header_bg_repeat"/> 
+0

मैं सापेक्ष लेआउट मैं ऐसा किया में रखा imageView का उपयोग कर छवि दोहराना चाहते हैं, लेकिन यह काम नहीं किया था –

+0

आप imageView में है कि बिटमैप चाहते मतलब? –

+0

हाँ छवि दृश्य –

2

सभी अनुरोधों में एक छोटी सी समस्या मौजूद है यदि आप छवि बहुत बढ़िया होंगी और आपके लेआउट का आकार छोटा होगा, छवि का आकार बदल जाएगा, केवल एक्स द्वारा दोहराए जाने के लिए आप इसे दोहरा सकते हैं।

मैं (सेट गुरुत्वाकर्षण भरने) इस तरह मेरी समस्या का समाधान

छवि

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
     android:src="@drawable/table_cells_bg_img" 
     android:tileMode="repeat" android:gravity="fill" /> 

और लेआउट

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="@dimen/table_cell_height"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="@dimen/table_cell_height" 
     android:scaleType="fitXY" 
     android:src="@drawable/table_cells_bg"/> 
<TextView 
     android:id="@+id/txtActivityTime" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/avatarImage" 
     android:text="TextView" 
     android:textColor="@color/white" 
     android:textSize="@dimen/font_size_middle" /> 
</RelativeLayout> 

और इसके साथ चौड़ाई = 1px और ऊंचाई छवि है table_cells_bg_img पर के लिए drawable bg = 1 पीएक्स

और लेआउट के आदि, तो अब आपकी छवि बैकग की तरह है दौर और यह मूल लेआउट

किसी भी आकार के आकार में बदल जाएगा, शायद मदद करें। मेरे मामले में साफ़ होने के लिए मुझे एक्स समन्वय द्वारा दोहराए गए टेबलसेल के पूर्ण आकार में टाइल पृष्ठभूमि छवि की आवश्यकता है (जैसे मैं इसे आईओएस पर कर सकता हूं)। इसलिए मैं इसका वर्णन करता हूं जैसे मैं वर्णन करता हूं।

संबंधित मुद्दे