2013-10-10 37 views
0

文本應該保存在圖像視圖中?文本不應該在佈局文件夾中定義,並應該從相應的鍵盤保存在圖像視圖上?圖片視圖上的文字視圖?

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.fullimage); 

     // get intent data 
     Intent i = getIntent(); 

     // Selected image id 
     int position = i.getExtras().getInt("id"); 
     ImageAdapter imageAdapter = new ImageAdapter(this); 

     ImageView imageView = (ImageView) findViewById(R.id.fullimage); 
     imageView.setImageResource(imageAdapter.mThumbIds[position]); 
    } 

} 
+1

使用相對佈局或FrameLayout裏 – Raghunandan

回答

1

使用的FrameLayout爲..上的TextView

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/thumbHolder"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/thumbImage" 
      android:scaleType="fitXY" /> 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="24dp" 
      android:id="@+id/titletxt" 
      android:gravity="center_vertical" 
      android:maxLines="2" 
      android:paddingRight="8dp" 
      android:paddingLeft="8dp" 
      android:textSize="16sp" 
      android:layout_gravity="bottom" 
      android:background="#80000000" 
      android:textColor="#ffffffff" 
      android:text="" /> 


    </FrameLayout> 

同時定義的ImageView和TextView的,並設置文本設置自定義字體: -

  1. 打造 「資產\ fonsts \」 文件夾然後將您的字體放在那裏
  2. 然後通過加載該字體創建字體: -

    Typeface tfBold = Typeface.createFromAsset(getActivity()。getAssets(),「fonts/Raleway-Bold.otf」);

  3. 然後設置字體在TextView中: -

    yourTextView.setTypeface(tfBold);

+0

那麼如何保存文本O,其圖像上不同字體的形象呢? – GOPATHI

+0

你可以使用不同的字體......讓我更新我的答案 – r4jiv007

+0

,然後如何自動保存圖像視圖上的文本,而無需拖放位置? – GOPATHI

0

嘗試這個 -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:background="@drawable/image"> 


     <LinearLayout 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:textSize="18sp" 
       android:textStyle="bold" 
       android:singleLine="true" 
       android:text="text"/> 

     </LinearLayout> 

    </LinearLayout> 
+0

不應該在佈局中定義文本不同的用戶以不同的方式鍵入他們的文本他們在圖像視圖中顯示? – GOPATHI

+0

然後使用android:visibility =「invisible」在佈局中設置可見性並以編程方式使其可見。 – gbl

0

您既可以在畫布上繪製圖像,然後在圖像上繪製文本,或者通過代碼創建佈局,並在佈局中設置文本視圖,然後將佈局放置在頂部圖像視圖背景的textview設置爲透明

0

只能使用TextView。以下面的方式使用drawableTopdrawableBottom,drawableLeft, drawableRight

<TextView 
    style="@style/layout_wrap" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:paddingRight="5dp" 
    android:drawableTop="@drawable/flags_00" 
    android:textColor="@color/text_color_tabs" 
    android:textStyle="bold" 
    android:maxLength="3" 
    android:gravity="center" 
    android:text="Team B" /> 

,並在通過以下方式

battingTeamFlag.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom); 
0

您可以使用按鈕並使用按鈕的背景設置image.and使用文本元素爲按鈕添加文本的代碼。

<Button 
    android:layout_width="wrap_parent" 
    android:layout_height="wrap_parent" 
    android:text="YourText" 
    android:background="@drawable/image" 
    > 
    </Button> 

根據你的要求,你可以從按鈕獲取文本並意圖通過它

+0

你能幫助我嗎? – GOPATHI

+0

看到我的回答我已更新.. –