2017-05-12 26 views
-1

喜在我的XML文件,我有這個包含的TextView和框架佈局的RelativeLayout:如何添加ImageView的到的FrameLayout編程

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="20dp"> 

     <EditText 
      android:id="@+id/id_send_EditText" 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:hint="@string/enter_text" 
      android:textColorHint="@color/com_facebook_button_background_color_disabled" 
      android:paddingRight="40dp" 
      android:layout_alignParentBottom="true" 
      android:isScrollContainer="true"/> 
     <FrameLayout 
      android:id="@+id/fl_pubCreate" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     </FrameLayout> 
    </RelativeLayout> 

我想創建一個ImageView的和編程方式將其添加到框架佈局。 如何做到這一點。 這是該怎麼做的工作富硒方法:

flayout = (FrameLayout)findViewById(R.id.frame_layout); 

private void mediaRecue() { 
     if(Pub_media_type.equalsIgnoreCase("image/jpeg")){ 
      ImageView imgMedia = new ImageView(getApplicationContext()); 
      Picasso.with(this) 
        .load(Pub_media_uri) 
        .placeholder(R.drawable.circular_progress_view) 
        .into(imgMedia); 
      //How to add img into flayout 

     }else if(Pub_media_type.equalsIgnoreCase("video/mp4")){ 
      VideoView videoView = new VideoView(getApplicationContext()); 
      //how to add Video into flayout 
     } 
    } 
+0

直接讓flayout.addView(imgMedia); –

+0

你有沒有使用過這個問題?它是如何將視圖添加到佈局中的基礎知識之一。你只需要調用'flayout.addView(imgMedia)'。唯一需要注意的是設置正確的LayuotParams,這取決於您希望圖像的顯示方式。 – Opiatefuchs

回答

0

簡單添加

flayout.addView(imgMedia); 
0

做這個

flayout.addView(imgMedia); 
+0

**來自複查隊列**:我可以請求您請您在答案中添加更多上下文。僅有代碼的答案很難理解。如果您可以在帖子中添加更多信息,它可以幫助提問者和未來的讀者。 – RBT

相關問題