嗨首先抱歉我的英语。 我有一个包含gridview的活动(更多)。想要与所有设备上的尺寸相同,但这就是我遇到问题的地方。 在星系s3看起来像我想要的,但在s2上测试它是创建行。行之间的空格包含图像中的图像和文本。 s3图像 https://drive.google.com/file/d/0BwFa2jI8Xt2qcGNqajdsMVVSd2c/edit?usp=sharing s2图像 https://drive.google.com/file/d/0BwFa2jI8Xt2qbmtmUERCRUVQNWs/edit?usp=sharing CustomGridViewAdapter -
package com.proonet.camareroporfavor;
import java.util.ArrayList;
import com.proonet.camareroporfavor.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomGridViewAdapter extends ArrayAdapter<ItemGridView> {
Context context;
int layoutResourceId;
ArrayList<ItemGridView> data = new ArrayList<ItemGridView>();
public CustomGridViewAdapter(Context context, int layoutResourceId,
ArrayList<ItemGridView> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RecordHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
ItemGridView item = data.get(position);
holder.txtTitle.setText(item.getTitle());
holder.imageItem.setImageBitmap(item.getImage());
return row;
}
static class RecordHolder {
TextView txtTitle;
ImageView imageItem;
}
}
ItemGridview
import android.graphics.Bitmap;
public class ItemGridView {
Bitmap image;
String title;
public ItemGridView(Bitmap image, String title) {
super();
this.image = image;
this.title = title;
}
public Bitmap getImage() {
return image;
}
public void setImage(Bitmap image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
我展示gridview的活动
public class InicioActivity extends ActionBarActivity {
private String[] opcionesMenu;
private DrawerLayout drawerLayout;
private ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
GridView gv;
ArrayList<ItemGridView> gridArray = new ArrayList<ItemGridView>();
CustomGridViewAdapter customGridAdapter;
private CharSequence tituloSeccion;
private CharSequence tituloApp;
TextView tVciudadDondeEstoy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inicio);
tVciudadDondeEstoy = (TextView) findViewById(R.id.ImageTextViewCiudadDondeEstoy);
cambioEnTextViewSegunCiudad ();
//Gridview
//set grid view item
Bitmap imagenVacia = BitmapFactory.decodeResource(this.getResources(), R.drawable.cuadro_vacio);
gridArray.add(new ItemGridView(imagenVacia,"Ofertas hoy"));
gridArray.add(new ItemGridView(imagenVacia,"Locales adheridos"));
gridArray.add(new ItemGridView(imagenVacia,"Mis Locales"));
gridArray.add(new ItemGridView(imagenVacia,"Locales cercanos"));
gridArray.add(new ItemGridView(imagenVacia,"Mis ofertas"));
gridArray.add(new ItemGridView(imagenVacia,"Locales cercanos"));
gridArray.add(new ItemGridView(imagenVacia,"algo"));
gridArray.add(new ItemGridView(imagenVacia,"algo2"));
gv = (GridView) findViewById(R.id.gridview);
customGridAdapter = new CustomGridViewAdapter(this, R.layout.row_grid, gridArray);
gv.setAdapter(customGridAdapter);
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(InicioActivity.this, "" + position, Toast.LENGTH_SHORT).show() ;
switch (position) {
case 0:
break;
case 1://boton ultimas ofertas,debe abrir la actividad ultimasOfertas de cada ciudad
if (CrearPerfil.ciudadSeleccionada.equals( "Alicante" )){
Intent intent = new Intent(InicioActivity.this, TipoDeLocalesActivity.class);
startActivity(intent);
}else{
Toast.makeText(InicioActivity.this, "No hay ofertas para tu localidad" , Toast.LENGTH_SHORT).show() ;}
break;
case 2:
break;
default:
}
}
});
xml:我在哪里有textview和imageview row_grid
<ImageView
android:id="@+id/item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cuadro_vacio" >
</ImageView>
<TextView
android:id="@+id/item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/item_image"
android:layout_alignTop="@+id/item_image"
android:layout_alignRight="@+id/item_image"
android:layout_alignBottom="@+id/item_image"
android:layout_marginTop="7dp"
android:layout_marginLeft="7dp"
android:gravity="left"
android:text="¿Donde estoy?"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:shadowColor="#c7c7c7"
android:shadowDx="3"
android:shadowDy="2"
android:shadowRadius="1.8">
</TextView>
</RelativeLayout>
我的活动xml:activity_inicio.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Contenido Principal -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#e3e3e3">
<ImageButton
android:id="@+id/ibtnCiudad"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/cuadro_vacio525x450" />
<!-- Texto que va dentro del imagebutton -->
<TextView
android:id="@+id/ImageTextViewCiudadDondeEstoy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/ibtnCiudad"
android:layout_alignRight="@+id/ibtnCiudad"
android:layout_alignTop="@+id/ibtnCiudad"
android:gravity="center"
android:shadowColor="#c7c7c7"
android:shadowDx="3"
android:shadowDy="2"
android:shadowRadius="1.8"
android:text=""
android:textColor="#ffffff"
android:textSize="25sp"
android:textStyle="bold" />
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/ibtnCiudad"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="3dp"
android:listSelector="#00000000"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="3dp" />
如果有人有行的解决方案,请查看所有的dispositipos,请告诉我。 我的意图是它看起来像flippboard应用程序。里面的行和文字 谢谢。