类似Facebook的GridView,在android上显示图像
我正在使用自定义库的Gridview布局 但没有达到我需要的结果 网格视图应根据最少1个图像和最多4个图像的图像数自动调整其列和行 news_default.xml类似Facebook的GridView,在android上显示图像,android,gridview,Android,Gridview,我正在使用自定义库的Gridview布局 但没有达到我需要的结果 网格视图应根据最少1个图像和最多4个图像的图像数自动调整其列和行 news_default.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.co
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/lib/com.rb.nonstop.HomeActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout android:id="@+id/rel_sender_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip">
<ImageView
android:id="@+id/img_news_sender_photo"
android:layout_width="70dip"
android:layout_height="70dip"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/txt_category"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/img_news_sender_photo"
android:textColor="#343434"
android:textSize="15dip"
android:text="News"
android:paddingLeft="5dip"
android:paddingTop="10dip"
/>
<View
android:id="@+id/view1"
android:layout_width="100dp"
android:layout_height="2dp"
android:background="@color/border"
android:layout_toRightOf="@+id/img_news_sender_photo"
android:layout_below="@+id/txt_category"
android:paddingLeft="20dip"
android:paddingTop="5dip" />
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/txt_sender_name_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/img_news_sender_photo"
android:layout_below="@+id/view1"
android:textColor="#343434"
android:textSize="15dip"
android:text="Karthik Kolanji, Mumbai"
android:paddingLeft="5dip"
android:paddingTop="5dip"
/>
</RelativeLayout>
<RelativeLayout android:id="@+id/rel_news_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@+id/rel_sender_photo">
<com.rb.lined.edittext.LinedEditText
android:id="@+id/edit_news"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:inputType="textMultiLine|textNoSuggestions"
android:padding="10dip"
android:singleLine="false"
android:imeOptions="actionNone"
android:textSize="10sp"
android:gravity="top|left"
android:minLines="10"
/>
</RelativeLayout>
<RelativeLayout android:id="@+id/rel_news_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@+id/rel_news_content"
>
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/txt_app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#343434"
android:textSize="10dip"
android:text="NewsFirst MobileApp"
android:paddingLeft="5dip"
android:paddingTop="5dip"
android:layout_alignParentLeft="true"
/>
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/txt_news_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#343434"
android:textSize="10dip"
android:text="September 10,2014 4:20 PM"
android:paddingLeft="5dip"
android:paddingTop="5dip"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<RelativeLayout android:id="@+id/rel_news_grid_photos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@+id/rel_news_date"
>
<com.jake.quiltview.QuiltView
android:id="@+id/quilt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dip"
app:scrollOrientation="horizontal|vertical" >
</com.jake.quiltview.QuiltView>
</RelativeLayout>
</RelativeLayout>
activity_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.rb.nonstop"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include android:id="@+id/rel_news_default"
layout="@layout/news_default"/>
</RelativeLayout>
HomeActivity.java
public class HomeActivity extends Activity{
public QuiltView quiltView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_home);
quiltView = (QuiltView) findViewById(R.id.quilt);
quiltView.setChildPadding(5);
addTestQuilts(200);
}
public void addTestQuilts(int num){
ArrayList<ImageView> images = new ArrayList<ImageView>();
for(int i = 0; i < num; i++){
ImageView image = new ImageView(this.getApplicationContext());
image.setScaleType(ScaleType.CENTER_CROP);
if(i % 2 == 0)
image.setImageResource(R.drawable.app_logo);
else
image.setImageResource(R.drawable.app_logo1);
images.add(image);
}
quiltView.addPatchImages(images);
}
}
我建议您使用RecyclerView与
在本例中,有一个很棒的教程。您应该看看QuiltView。。非常感谢您的快速回复。。。让我实现这个…@Rat-a-tat-a-tat Ratatouille-->我尝试实现库。。。它显示错误膨胀类com.jake.quiltview.quiltview。。我正确地配置了它。花了一整天的时间解决错误。什么都没用:检查你的构建路径,可能它无法获取库。。发布您得到的日志错误。。还要检查一下,如果你需要一个xlmns属性,如果是3张图片,那么它应该像我发布的示例图片一样分成3张。如果1个图像,则1个分割;如果2个图像,则2个分割;如果4个图像,则4个分割