画廊布局问题

问题描述:

我正在尝试在我的Android项目中创建一个画廊,但似乎无法使其正常工作。画廊布局问题

这里是我想要做的事:

基本上,我想只能显示图片的画廊,但仍具有相同的控件(滑动左和右)。我从互联网异步获取图片。

我在那里?

那么,现在我只是试图展示画廊...我会看到后面的“一个图片”步骤。

我的问题是什么?

呃......我的画廊没有显示在我的布局上。完全一样。

什么似乎是问题?

日志信息给我说的身高和我的画廊对象的widht是... 0

谈到代码...

Layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="@drawable/fond"> 

    <ImageView android:background="@drawable/banniere" android:layout_height="wrap_content" android:layout_width="fill_parent"/> 

    <Gallery 
    android:id="@+id/gallery" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
/> 



</LinearLayout> 

活动

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.galleryfullscreen); 

    Gallery gal = (Gallery) findViewById(R.id.gallery); 

    ArrayList<Photo> photos = (ArrayList<Photo>) this.getIntent().getExtras().getSerializable("Photos"); 
    int pos = this.getIntent().getExtras().getInt("Index"); 

    Log.i("Season",photos.toString()); 

    gal.setAdapter(new PhotoAdapter(this, photos, false)); 
    gal.setSelection(pos); 

    Log.d("Bottom", String.valueOf(gal.getBottom())); 
    Log.d("Right", String.valueOf(gal.getRight())); 
    Log.d("Width", String.valueOf(gal.getWidth())); 
    Log.d("Height", String.valueOf(gal.getHeight()));  
} 

其他设置正确。

适配器

公共类PhotoAdapter延伸BaseAdapter {

private ArrayList<PhotoView> views; 
private ArrayList<Photo> season; 

public PhotoAdapter(Context c, ArrayList<Photo> images, boolean mini) { 

    season = images; 
    views = new ArrayList<PhotoView>(); 
    for (int i = 0; i < images.size() ; i++) 
     if (mini) 
     views.add(new PhotoView(c,images.get(i).getUrlMini(),false)); 
     else{ 

      views.add(new PhotoView(c,images.get(i).getUrlBig(),true)); 
     } 

} 

@Override 
public int getCount() { 
    return views.size(); 
} 

@Override 
public Object getItem(int position) { 
    return views.get(position); 
} 

@Override 
public long getItemId(int position) { 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    return views.get(position); 
} 

public ArrayList<Photo> getSeason() { 
    return season; 
} 

}

该适配器工作正常进行的其他对象(如GridView控件)

而PhotoView中...

public class PhotoView e xtends ImageView {

Bitmap image; 

public PhotoView(Context context, String url, boolean Gallery) { 

    super(context); 
    if (!Gallery){ 
    this.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT,GridView.LayoutParams.WRAP_CONTENT)); 
    this.setScaleType(ImageView.ScaleType.FIT_CENTER); 
    this.setImageDrawable((getResources().getDrawable(R.drawable.blk))); 
    new DownloadImageTask().execute(url); 
    } 
    else{ 
     this.setLayoutParams(new Gallery.LayoutParams(100,100)); 
     this.setScaleType(ImageView.ScaleType.FIT_CENTER); 
     this.setBackgroundDrawable(((getResources().getDrawable(R.drawable.blk)))); 
     this.setImageDrawable((getResources().getDrawable(R.drawable.blk))); 
    } 

} 

public Bitmap getImage(){ 
    return image; 
} 

public void setImage(Bitmap img){ 
    image = img; 
    this.setImageBitmap(image); 
} 

同样,它的网格视图工作正常。通过下载任务,尚未为图库设置。我至少在设置这个之前试图显示一个资源,所以我相信这个问题不是来自这里。

Sooo ...为什么我的日志显示“0”的画廊宽度和高度? LayoutParams是为对象设置的(我尝试了XML和代码)以及里面的视图。这些项目被创建,并且调用“getView”方法。我试着在这里布置LayoutParams,不会改变任何东西。

我也尝试在画廊的布局中添加xmlns:android =“http://schemas.android.com/apk/res/android”部分,但没有改变任何事情。

我真的不知道我错过了什么。我试图修改很多关于画廊对象的教程,但仍然......不知道! 如果您对我应该做什么/尝试有任何想法,请...

谢谢大家!

干杯

看着你的XML文件,我可以看到什么可能是问题。您的LinearLayout被设置为以水平方式添加视图(这是默认设置),并且您的第一个视图的layout_width设置为fill_parent。

在您的LinearLayout中将方向设置为垂直。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@drawable/fond"> 
+0

那么,那是做伎俩..知道我错过了什么!非常感谢 – Ours 2010-10-21 20:38:07