2013-04-09 53 views
0

我有一个扩展SherlockActivity的活动,并且使包含3个不同片段的视图膨胀。更改一个片段的ImageView会对另一个片段的布局造成不必要的更改

片段1:

<TextView 
    android:id="@+id/tvTodayCal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_margin="5dp" 
    android:text="@string/tod_cal" 
    android:textAppearance="@style/TitleBlackFont" /> 

<TextView 
    android:id="@+id/tvTotalCalorNumb" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/tvRespBudget" 
    android:layout_marginRight="5dp" 
    android:layout_toLeftOf="@+id/tvRespBudget" 
    android:text="@string/summ_3" 
    android:textAppearance="@style/NumberGreenFont" /> 

<TextView 
    android:id="@+id/tvRespBudget" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/btAddExer" 
    android:layout_alignLeft="@+id/btAddExer" 
    android:layout_marginBottom="15dp" 
    android:text="@string/un_bud" 
    android:textAppearance="@style/RedLittleFont" /> 

<Button 
    android:id="@+id/btAddExer" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="10dp" 
    android:layout_marginLeft="2dp" 
    android:layout_marginRight="5dp" 
    android:layout_toLeftOf="@+id/ivGlass01" 
    android:text="@string/bt_add_exer" /> 

<Button 
    android:id="@+id/btAddFood" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/btAddExer" 
    android:layout_marginLeft="5dp" 
    android:layout_toLeftOf="@+id/btAddExer" 
    android:text="@string/bt_add_food" /> 

<ImageView 
    android:id="@+id/ivGlass08" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/ivGlass07" 
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp" 
    android:src="@drawable/vaso_vacio" /> 


<ImageView 
    android:id="@+id/ivGlass07" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/ivGlass06" 
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp" 
    android:src="@drawable/vaso_vacio" /> 

<ImageView 
    android:id="@+id/ivGlass06" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/ivGlass05" 
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp" 
    android:src="@drawable/vaso_vacio" /> 

<ImageView 
    android:id="@+id/ivGlass05" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/ivGlass04" 
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp" 
    android:src="@drawable/vaso_vacio" /> 

<ImageView 
    android:id="@+id/ivGlass04" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/ivGlass03" 
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp" 
    android:src="@drawable/vaso_vacio" /> 

<ImageView 
    android:id="@+id/ivGlass03" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/ivGlass02" 
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp" 
    android:src="@drawable/vaso_vacio" /> 

<ImageView 
    android:id="@+id/ivGlass02" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/ivGlass01" 
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp" 
    android:src="@drawable/vaso_vacio" /> 

<ImageView 
    android:id="@+id/ivGlass01" 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_marginBottom="10dp" 
    android:layout_marginRight="5dp" 
    android:clickable="true" 
    android:src="@drawable/vaso_vacio" /> 

</RelativeLayout> 

fragment2:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Esto es health... " 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

和fragment3:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/llTable" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_weight="0" 
android:background="#66D1FABE" 
android:padding="5dp" > 

<View 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="#aaa" /> 

<TableRow 
    android:id="@+id/tableRow1" 
    android:layout_height="wrap_content" 
    android:background="#000000" 
    android:weightSum="4" > 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvBudgetTitle" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/budg_tit" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvFoodTitle" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/food_tit" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvExerciseTitle" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/exce_tit" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvTotalTitle" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/total_tit" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 
</TableRow> 

<TableRow 
    android:id="@+id/tableRow2" 
    android:layout_height="wrap_content" 
    android:background="#000000" 
    android:weightSum="4" > 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvBudgetQty" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="1178" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvFoodQty" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="620" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvExerciseQty" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="120" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <TextView 
     android:id="@+id/tvTotalQty" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="1980" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 
</TableRow> 

<View 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="#aaa" /> 

</TableLayout> 

我需要切换的ImageView dynamicall Ÿ当用户选择它,所以在我的主要活动中,我使用:

iGlass2 = (ImageView) findViewById(R.id.ivGlass02); 
iGlass2.setOnClickListener(this); 
iGlass2.setImageResource(R.drawable.vaso_lleno); 

一切其确定(我上布局新的图像),但我失去了我的片段3的格式(其中的方式是一个2行4列的TableLayout)。

我已尽一切努力修复它,但对我来说不可能...有人可以帮我吗?

回答

0

我刚刚通过将TableLayout中的fragment3更改为LinearLayouts的组合来执行相同的表来解决此问题。

现在我fragment3样子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/llTable" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#66D1FABE" 
android:orientation="vertical" 
android:padding="5dp" > 

<View 
    android:id="@+id/upperBar1" 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="#aaa" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="4" > 

    <View 
     android:id="@+id/verticalUpBar1" 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#000000" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/tvBudgetTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="@string/budg_tit" /> 

     <TextView 
      android:id="@+id/tvBudgetQty" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="1178" /> 
    </LinearLayout> 

    <View 
     android:id="@+id/verticalUpBar2" 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#000000" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/tvFoodTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="@string/food_tit" /> 

     <TextView 
      android:id="@+id/tvFoodQty" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="620" /> 
    </LinearLayout> 

    <View 
     android:id="@+id/verticalUpBar3" 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#000000" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/tvExerciseTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="@string/exce_tit" /> 

     <TextView 
      android:id="@+id/tvExerciseQty" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="120" /> 
    </LinearLayout> 

    <View 
     android:id="@+id/verticalUpBar4" 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#000000" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/tvTotalTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="@string/total_tit" /> 

     <TextView 
      android:id="@+id/tvTotalQty" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="1980" /> 
    </LinearLayout> 

    <View 
     android:id="@+id/verticalUpBar5" 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:background="#aaa" /> 
</LinearLayout> 

<View 
    android:id="@+id/lowerBar" 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="#aaa" /> 

</LinearLayout>