2017-04-21 21 views
-5

我在機器人編程 初學者我有點困惑選擇佈局我的報告,因爲有像由於GridViewGridLayoutTableLayout等 這麼多的佈局,我基本的web我認爲做出這樣的網絡使用表的報表,顯示一個類似的DataGrid數據陣列如何選擇必要的Android報表佈局

我希望報告是這樣的:

Report that I want

我用GridView,但它是不像預期的那樣。 感謝您的幫助。


我目前的編碼,從而導致

PHP result

public class fragment_result_listab extends Fragment { 
View list_ab_result; 
String selectresult_ab; 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    list_ab_result= inflater.inflate(R.layout.fragment_result_listab,container,false); 

    GridView gv = (GridView) list_ab_result.findViewById(R.id.listab); 
    //value from other fragment (result from php) 
    selectresult_ab = getArguments().getString("trans_value"); 


    String[] nselectresult=selectresult_ab.split(","); 

    List<String> resultlist=null; 


    resultlist = new ArrayList(); 
    for(int i = 0; i < nselectresult.length; i++) { 
     resultlist.add(resultlist.size(),nselectresult[i]); 

    } 

    final ArrayAdapter<String> gridViewArrayAdapter = new ArrayAdapter<String>(getActivity(),R.layout.cell_gridview, resultlist); 
    gv.setAdapter(gridViewArrayAdapter); 


    return list_ab_result; 

} 

}

fragment_result_listab.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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="@color/mybg" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     tools:ignore="UselessParent"> 
     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:gravity ="center" 
      android:fillViewport="true" 
      android:layout_marginTop="0dp" 
      android:layout_marginLeft="0dp" 
      android:layout_marginRight="0dp" 
      android:id="@+id/scrollViewlistab" 
      tools:ignore="ObsoleteLayoutParam,UselessParent"> 
      <GridView 
       android:id="@+id/listab" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:numColumns="4" 
       tools:ignore="NestedScrolling"> 
      </GridView> 
     </ScrollView> 
    </LinearLayout> 
</LinearLayout> 

cell_gridview XML

<?xml version="1.0" encoding="utf-8"?> 
    <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@color/mybgwhite" 
     android:lines="5" 
     android:maxLines="5" 
     android:padding="5dp"/> 

當前報告

Current Result

+2

「但它並不如預期。」你期望什麼?你得到了什麼?你使用什麼代碼?沒有這些東西,我們無法回答。 (爲了記錄,GridView不可能是你需要的,它不會做web程序員所期望的。你可能想要ListView或RecyclerView) –

+0

代碼添加了java和xml –

回答