2017-03-18 33 views
0

我有一个小问题。在我的表格行中,我想添加一个FacebookProfilePictureView,除了添加一个简单的ImageView外,这会导致一些错误。我附上了一张显示我收到的输出的图片。动态添加facebook个人资料图片在表格行中查看android

enter image description here

白框的序列号的右边是profilepicview设置,所有的时间。另外,在xml中,我将大小设置为50,50(宽度,高度),但在java中它变得杂乱。我的代码如下。

XML代码:

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/view_below_linear_layout_three_team_spuck" 
    android:id="@+id/the_maintable_team_spuck" 
    > 

    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/the_maintable_row_team_spuck"> 

     <com.facebook.login.widget.ProfilePictureView 
      android:id="@+id/profile_pic_view_team_spuck" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:visibility="gone" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

    </TableRow> 
</TableLayout> 

Java代码:

the_normal_image_view = new ImageView(view.getContext()); // this is the normal image view, no issues when adding this in table 
profilePictureView = new ProfilePictureView(view.getContext()); // this is the profile pic view 


the_maintable_row_team_spuck.removeAllViews(); 
the_maintable_row_team_spuck.setLayoutParams(new TableRow.LayoutParams 
     (TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); 

the_maintable_row.setBackgroundResource(R.drawable.cell_shape); 


/*the_smallperson_team_spuck.setImageResource(R.drawable.the_smallperson); 
the_smallperson_team_spuck.setPadding(7, 7, 15, 0);*/ 


profilePictureView.setPadding(7, 7, 15, 0); 

//the_maintable_row.addView(the_normal_image_view); // adding normal image view into row 
the_maintable_row.addView(profilePictureView);   // adding fb profile pic view in to row 

the_maintable.addView(the_maintable_row_team_spuck, new TableRow.LayoutParams 
     (TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); 

任何帮助,将不胜感激,谢谢:)

回答

1

如果你想,然后加载用户简介的图片到的ImageView您应该试试这个

第1步 Ima geView

<ImageView 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/profile_image" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:src="@drawable/back" 
    app:civ_border_width="2dp" 
    app:civ_border_color="@color/colorWhite"/> 

步骤2把这个线路上onCreate方法时打开屏幕

new DownloadImage(imgUserProfile).execute(userProfileUrl); 

步骤3 MainActivity.java

super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_home); 
ImageView imgUserProfile; 
imgUserProfile = (ImageView).findViewById(R.id.profile_image); 

步骤4方法加载图像对于AcyncTask Mehod名称:DownloadImage()

public class DownloadImage extends AsyncTask<String, Void, Bitmap> { 
    CircleImageView bmImage; 

    public DownloadImage(ImageView bmImage) { 
     this.bmImage = (CircleImageView) bmImage; 
    } 

    protected Bitmap doInBackground(String... urls) { 
     String urldisplay = urls[0]; 
     Bitmap mIcon11 = null; 
     try { 
      InputStream in = new java.net.URL(urldisplay).openStream(); 
      mIcon11 = BitmapFactory.decodeStream(in); 
     } catch (Exception e) { 
      Log.d("Error", e.getStackTrace().toString()); 

     } 
     return mIcon11; 
    } 

    protected void onPostExecute(Bitmap result) { 
     bmImage.setImageBitmap(result); 
    } 
} 
+0

如果我有朋友的ID,那么该怎么办? –

+0

但你在哪里使用朋友的ID? 我想你只想显示个人资料照片仪式? –

+0

我们可以使用朋友IDS来获取图片我认为... –

相关问题