我有一个小问题。在我的表格行中我想添加一个FacebookProfilePictureView,除了添加一个简单的ImageView之外,这会给我带来一些错误。我附上的图片显示了我收到的输出。
序列号右侧的白框是始终设置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));
感谢任何帮助,谢谢:)
答案 0 :(得分:1)
如果要将用户个人资料图像加载到ImageView,那么您应该尝试这个
第1步 ImageView
<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);
适用于AcyncTask Mehod的第4步方法名称: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);
}
}