2013-05-20 24 views
0

我正面临着一个令我发疯的问题。就是这样。我有一个展开媒体文件的可扩展列表活动。一组是音频文件,另一组是图像文件。 AudioGroup的孩子有一个布局,ImageGroup的孩子有另一个不同的布局。这是我使用Android ExpandableList活动孩子的android:layout_weight不能正常工作

代码

扩展列表适配器,CHILDVIEW PART

@Override 
public View getChildView(int groupPosition, int childPosition, 
     boolean isLastChild, View convertView, ViewGroup parent) { 
    inflaterChild=activity.getLayoutInflater(); 
    convertView=null; 

    //seleccionamos el layout que nos convenga en funcion de si es audio o imagen 

    //audio 
    if(mediaObjects.get(groupPosition).getFiles().get(childPosition).getTipo()==1){ 
     viewChild=inflaterChild.inflate(R.layout.layout_child_media_musica, null); 
     descripcion=(TextView)viewChild.findViewById(R.id.descripcionMusica); 
     descripcion.setText(Html.fromHtml(mediaObjects.get(groupPosition).getFiles().get(childPosition).getDescripcion())); 
    } 

    //imagen 
    if(mediaObjects.get(groupPosition).getFiles().get(childPosition).getTipo()==2){   
     viewChild=inflaterChild.inflate(R.layout.layout_media_imagenes, null);    
     thumbnail=(ImageView)viewChild.findViewById(R.id.thumbnailMedia); 
     thumbnail.setImageResource(R.drawable.portada); 
     descripcion=(TextView)viewChild.findViewById(R.id.descripcionImagen); 
     descripcion.setText(Html.fromHtml(mediaObjects.get(groupPosition).getFiles().get(childPosition).getDescripcion())); 
    } 
    return viewChild; 
} 

布局方法AUDIOGROUP

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    tools:context=".Media" 
    android:orientation="vertical" 
    android:id="@+id/childMediaMusica" 
    android:weightSum="100"> 

    <TextView 
     android:id="@+id/descripcionMusica" 
     android:layout_height="0dp" 
     android:layout_weight="30" 
     android:layout_width="match_parent"/> 

    <LinearLayout 
     android:id="@+id/contenedorBotones" 
     android:layout_height="0dp" 
     android:layout_weight="70" 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:weightSum="100"> 

     <Button 
      android:id="@+id/playStop" 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="50"/> 

     <Button 
      android:id="@+id/down" 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="50"/>   
    </LinearLayout> 

</LinearLayout> 

布局方法IMAGEGROUP

<?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="fill_parent" 
    android:layout_height="wrap_content" 
    tools:context=".Media" 
    android:orientation="horizontal" 
    android:weightSum="100"> 

    <ImageView 
     android:id="@+id/thumbnailMedia" 
     android:layout_width="0dp" 
     android:layout_weight="35" 
     android:layout_height="50dp" 
     android:scaleType="fitXY" 
     android:contentDescription="@string/desc"/> 

    <TextView 
     android:id="@+id/descripcionImagen" 
     android:layout_width="0dp" 
     android:layout_weight="65" 
     android:layout_height="50dp"/> 

</LinearLayout> 

正如你可以看到它的一个非常简单的代码。嗯,这就是结果:

enter image description here

AudioGroup布局不充盈整个宽度。 ImageGroup布局很混乱,就像看不到我写的重量。

有谁知道这到底是怎么回事?

件事是我已经测试:

  • 在每个布局主要的LinearLayout FILL_PARENT,match_parent,WRAP_CONTENT等的每一个组合。

  • 尝试做的事情只能用DP meassure(即工作,但不是我想要的东西)

  • 尝试使用上ImageGroup布局

  • 使用ViewHolder和convertView东西另一个图像来管理内部布局getChildView方法

任何这些事情(除了使用dp大小)的作品,但我打开建议甚至如果意味着再做一次。

谢谢大家

回答

0

JODERRR POR FIN!

好吧,我刚解决它。我带了我其他3 f * *小时。这很简单,正如设置ExpandableList布局那样:

<ExpandableListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="90" 
    android:choiceMode="singleChoice"/> 

在第一时刻,我将layout_width设置为wrap_content。我不敢相信我没注意到它之前