2017-09-05 56 views
0

我在制作android布局 时遇到问题,您可以在下面的图像中看到图像。本书的第四个图像进行自动调整,我需要往下移动时的布局完成后androidview中的imageview不会向下移动,只能水平扩展,因此一些图像不会显示

android layout problem

到目前为止我的代码是

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/backgroundmap" 
    android:isScrollContainer="true" 
    tools:context="com.example.adeel.freelancerproject.fileexpansion"> 


<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

<LinearLayout 
    android:layout_width="150dp" 
    android:layout_height="match_parent" 
    android:id="@+id/fileshelf" 
    android:padding="10dp" 
    android:orientation="horizontal" 
    > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/bluebook"/> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/bluebook"/> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/bluebook"/> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/bluebook"/> 

</LinearLayout> 

</ScrollView> 
</RelativeLayout> 

基本上我需要修复布局的宽度完成后剩下的图像向下移动。 请帮忙 谢谢问候

+0

您是否考虑过使用RecyclerView?看起来你想制作一个可滚动列表。 –

回答

0

您可以使用GridLayout并设置您想要的列和行。

您也可以使用FlowLayouthttps://github.com/ApmeM/android-flowlayout。如果该行被填充,则下一个视图将位于该行的下方。

+0

非常感谢..它像一个魅力工作 –

0

您可以在GridLayoutManager中使用RecyclerView。 GridLayoutManager接受spanCount作为构造参数

public GridLayoutManager(Context context, int spanCount) { 
    super(context); 
    setSpanCount(spanCount); 
} 

这是多么我已经使用了。

在活动,可以说,光催化活性,

mAdapter = new ImageAdapter(this, images); 
recycledImageList.setAdapter(mAdapter); 
recycledImageList.setLayoutManager(new GridLayoutManager(this, 2)); 

ImageAdapter就像其他RecyclerView适配器和photoactivity.xml期望一个recyclerView内。