Je travaille sur un logiciel qui affiche les cartes du cerveau. J'ai plusieurs cartes qui sont actualisées à chaque itération du temps. Je voudrais diplay ces carte dans une mise en page de table zoomable, donc j'utiliser la classe AwesomeTableLayout.java
(juste un TableLayout de base pour commencer):Comportement bizarre surfaceView dans TableLayout
public class AwesomeTableLayout extends TableLayout{
public AwesomeTableLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public AwesomeTableLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
}
Chaque carte sont diplayed en utilisant un SurfaceView appelé MapView:
public class MapView extends SurfaceView implements SurfaceHolder.Callback {
Je veux ajouter ces cartes de manière progammatique, puis l'utilisateur peut supprimer/ajouter une autre carte (entrée, mémoire, mise au point, etc.).
Donc, dans mon MainActivity
je fais:
public class MainActivity extends Activity {
//...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources r = getResources();
XmlResourceParser parser = r.getXml(R.layout.activity_main);
AttributeSet as = Xml.asAttributeSet(parser);
Context context = getApplicationContext();
mMapView = new MapView(context, as);
mMapView2 = new MapView(context, as);
AwesomeTableLayout tl = (AwesomeTableLayout) findViewById(R.id.layout);
TableRow tr = new TableRow(this);
tr.addView(new AddMapOrStatsView(context, 0, 0));
tr.addView(mMapView2);
tr.addView(mMapView);
tr.addView(new AddMapOrStatsView(context, 0, 1));
tr.addView(new AddMapOrStatsView(context, 0, 2));
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
}
La classe AddMapOrStatsView
est juste une sorte de « ajouter » image pour ajouter une nouvelle carte sur la table (l'image est l'étranger d'Android):
public class AddMapOrStatsView extends ImageView{
public AddMapOrStatsView(Context context,final int ligne,final int colonne) {
super(context);
/* image utilisée */
setImageResource(R.drawable.ic_launcher);
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Un click simple sur l' AddMapOrStatsView("+ligne+","+colonne+") a été effectué !");
}
});
}
}
le activity_main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<com.main.gui.AwesomeTableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <!-- 2 columns -->
<!-- <TableRow -->
<!-- android:id="@+id/tableRow1" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:padding="5dip" > -->
<!-- <TextView -->
<!-- android:id="@+id/textView1" -->
<!-- android:text="Column 1" -->
<!-- android:textAppearance="?android:attr/textAppearanceLarge" /> -->
<!-- <Button -->
<!-- android:id="@+id/button1" -->
<!-- android:text="Column 2" /> -->
<!-- <Button -->
<!-- android:id="@+id/buttonxx" -->
<!-- android:text="Column 3" /> -->
<!-- </TableRow> -->
</com.main.gui.AwesomeTableLayout>
maintenant, ici p roblem. Si je lance l'application avec le code précédent je vois ceci:
comme vous pouvez le voir, je ne vois que les 3 vues AddMapOrStatView.
Si je décommenter le code XML comme ceci:
<?xml version="1.0" encoding="utf-8"?>
<com.main.gui.AwesomeTableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <!-- 2 columns -->
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/textView1"
android:text="Column 1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:text="Column 2" />
<!-- <Button -->
<!-- android:id="@+id/buttonxx" -->
<!-- android:text="Column 3" /> -->
</TableRow>
</com.main.gui.AwesomeTableLayout>
Je vois ceci:
Si je clique sur je vois le jeu (à savoir que je dessine les deux surfaceView) ceci:
Enfin, je décommenter mon xml comme ceci:
<?xml version="1.0" encoding="utf-8"?>
<com.main.gui.AwesomeTableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <!-- 2 columns -->
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/textView1"
android:text="Column 1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:text="Column 2" />
<Button
android:id="@+id/buttonxx"
android:text="Column 3" />
</TableRow>
</com.main.gui.AwesomeTableLayout>
Je vois ceci:
quand je dessine deux vue de la surface, je vois ceci:
La chose est, je veux juste voir les 3 photos de l'androïde et les deux cartes. Pourquoi diable dois-je ajouter d'autres choses dans la rangée de tableLayout pour voir ma vue de surface?
Merci d'avoir lu.