浏览代码

3row Grid

tobiasKaminsky 10 年之前
父节点
当前提交
3cab2038a3

+ 22 - 19
res/layout/grid_image.xml

@@ -15,36 +15,32 @@
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   
 -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/ListItemLayout"
-    android:layout_width="fill_parent"
-    android:layout_height="160dp"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_gravity="center_horizontal"
     android:background="@drawable/list_selector"
-    android:orientation="horizontal" >
+    android:gravity="center_horizontal"
+    android:orientation="vertical" >
 
-    <ImageView
+    <com.owncloud.android.ui.SquareImageView
         android:id="@+id/imageView1"
-        android:layout_width="150dp"
-        android:layout_height="150dp"
-        android:layout_marginBottom="5dp"
-        android:layout_marginLeft="9dp"
-        android:layout_marginTop="5dp"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_gravity="fill"
+        android:paddingLeft="10dp"
+        android:paddingRight="10dp"
+        android:scaleType="centerCrop"
         android:src="@drawable/ic_menu_archive" />
 
-    <ImageView
-        android:id="@+id/imageView2"
-        android:layout_width="40dp"
-        android:layout_height="22dp"
-        android:layout_marginLeft="22dp"
-        android:src="@drawable/local_file_indicator" />
-
     <FrameLayout
         android:id="@+id/imageItemFrame"
-        android:layout_width="56dp"
-        android:layout_height="56dp"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
         android:focusable="false"
         android:focusableInTouchMode="false" >
 
@@ -115,4 +111,11 @@
             android:textSize="12dip" />
     </FrameLayout>
 
+    <ImageView
+        android:id="@+id/imageView2"
+        android:layout_width="40dp"
+        android:layout_height="22dp"
+        android:layout_marginLeft="22dp"
+        android:src="@drawable/local_file_indicator" />
+
 </LinearLayout>

+ 10 - 7
res/layout/grid_item.xml

@@ -20,27 +20,30 @@
 -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/ListItemLayout"
-    android:layout_width="fill_parent"
-    android:layout_height="160dp"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_gravity="center_horizontal"
     android:background="@drawable/list_selector"
+    android:gravity="center"
     android:orientation="vertical" >
 
     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="90dp"
-        android:layout_height="93dp"
-        android:layout_marginBottom="5dp"
-        android:layout_marginLeft="9dp"
-        android:layout_marginTop="5dp"
+        android:layout_height="90dp"
+        android:layout_marginLeft="10dp"
+        android:layout_marginRight="10dp"
         android:src="@drawable/ic_menu_archive" />
 
     <TextView
         android:id="@+id/Filename"
-        android:layout_width="95dp"
+        android:layout_width="100dp"
         android:layout_height="wrap_content"
+        android:layout_gravity="center_horizontal"
         android:layout_marginLeft="4dp"
         android:layout_marginRight="4dp"
         android:ellipsize="middle"
+        android:gravity="center_horizontal"
         android:singleLine="true"
         android:text="TextView"
         android:textColor="#303030"

+ 4 - 3
res/layout/list_fragment.xml

@@ -32,13 +32,14 @@
             android:id="@+id/list_root"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:columnWidth="160dp"
+            android:columnWidth="100dp"
             android:gravity="center"
-            android:horizontalSpacing="10dp"
+            android:horizontalSpacing="2dp"
             android:numColumns="auto_fit"
             android:stretchMode="columnWidth"
-            android:verticalSpacing="10dp"
+            android:verticalSpacing="2dp"
             android:visibility="visible" />
+
     </android.support.v4.widget.SwipeRefreshLayout>
 
     <android.support.v4.widget.SwipeRefreshLayout

+ 10 - 12
src/com/owncloud/android/ui/ExtendedListView.java

@@ -22,10 +22,9 @@ import android.content.Context;
 import android.graphics.Canvas;
 import android.util.AttributeSet;
 import android.widget.GridView;
-import android.widget.ListView;
 
 /**
- * ListView allowing to specify the position of an item that should be centered in the visible area, if possible.
+ * GridView allowing to specify the position of an item that should be top left in the visible area, if possible.
  * 
  * The cleanest way I found to overcome the problem due to getHeight() returns 0 until the view is really drawn. 
  *  
@@ -33,7 +32,7 @@ import android.widget.ListView;
  */
 public class ExtendedListView extends GridView {
 
-    private int mPositionToSetAndCenter;
+    private int mPositionToSetTopLeft;
 
     public ExtendedListView(Context context) {
         super(context);
@@ -46,7 +45,7 @@ public class ExtendedListView extends GridView {
     public ExtendedListView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
     }
-
+    
     /**
      * {@inheritDoc}
      * 
@@ -55,21 +54,20 @@ public class ExtendedListView extends GridView {
     @Override
     protected void onDraw (Canvas canvas) {
         super.onDraw(canvas);
-        if (mPositionToSetAndCenter > 0) {
-            this.setSelection(mPositionToSetAndCenter);
-            //this.setSelectionFromTop(mPositionToSetAndCenter, getHeight() / 2);
-            mPositionToSetAndCenter = 0;
+        if (mPositionToSetTopLeft > 0) {
+            this.smoothScrollToPosition(mPositionToSetTopLeft);
+            mPositionToSetTopLeft = 0;
         }
     }
     
     /**
-     * Public method to set the position of the item that should be centered in the visible area of the view.
+     * Public method to set the position of the item that should be top left in the visible area of the view.
      * 
      * The position is saved here and checked in onDraw().
      *  
-     * @param position         Position (in the list of items) of the item to center in the visible area.     
+     * @param position         Position (in the list of items) of the item to be top left in the visible area.     
      */
-    public void setAndCenterSelection(int position) {
-        mPositionToSetAndCenter = position;
+    public void setSelectionAsTopLeft(int position) {
+        mPositionToSetTopLeft = position;
     }
 }

+ 25 - 0
src/com/owncloud/android/ui/SquareImageView.java

@@ -0,0 +1,25 @@
+package com.owncloud.android.ui;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+public class SquareImageView extends ImageView {
+
+    public SquareImageView(Context context) {
+        super(context);
+    }
+
+    public SquareImageView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
+    }
+}

+ 4 - 0
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -180,6 +180,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                 localStateView.setVisibility(View.INVISIBLE);
             }
             
+            if (!fileView){
+                localStateView.setVisibility(View.GONE);
+            }
+            
             TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
             TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
             ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);

+ 2 - 10
src/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -201,22 +201,14 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
             
             int top = mTops.remove(mTops.size() - 1);
             
-            imageView.setSelection(firstPosition);
+            imageView.smoothScrollToPosition(firstPosition);
             
             // Move the scroll if the selection is not visible
             int indexPosition = mHeightCell*index;
             int height = imageView.getHeight();
             
             if (indexPosition > height) {
-                if (android.os.Build.VERSION.SDK_INT >= 11)
-                {
-                    imageView.smoothScrollToPosition(index); 
-                }
-                else if (android.os.Build.VERSION.SDK_INT >= 8)
-                {
-                    imageView.setSelection(index);
-                }
-                
+                imageView.smoothScrollToPosition(index);
             }
         }
     }