2015-03-20 7 views
1

Я хочу отобразить один из макетов во время выполнения на основе некоторого состояния и названный макет принять площадь зала родительского макета.Xml Layout in android

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="348dp" 
    android:text=" " 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 



<LinearLayout 
    android:id="@+id/linearlayoutdesign1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/imageView1" 
    android:layout_alignLeft="@+id/textView1" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:orientation="vertical" > 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:id="@+id/linearlayoutdesign" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

<FrameLayout 
    android:id="@+id/textaddress" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_toLeftOf="@+id/linearlayoutdesign1" 
    android:background="#000000"> 


    <TextView 
    android:id="@+id/txtadd" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:textSize="12sp" 
    android:textColor="#FFFFFF" 
    android:hint=" Please wait for Location Trace..."/> 

</FrameLayout>  
<FrameLayout 
    android:id="@+id/videoview" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_below="@+id/textaddress" 
    android:layout_toLeftOf="@+id/textView1" > 

</FrameLayout> 



<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="24dp" 
    android:src="@drawable/submitgreen" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/linearlayoutdesign1" 
    android:layout_alignParentBottom="true" 
    android:src="@drawable/startgreen" /> 

<ImageView 
    android:id="@+id/recordstatus_imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView2" 
    android:layout_marginLeft="18dp" 
    android:layout_toRightOf="@+id/imageView1" 
    android:src="@drawable/recording" /> 

...................

if(flag) 
    linearLayout.addView(tableRow, new LinearLayout.LayoutParams 
          (tableRow.getLayoutParams().MATCH_PARENT, tableRow.getLayoutParams().MATCH_PARENT)); 
       else 
    linearLayout.addView(tableRow, new LinearLayout.LayoutParams 
          (tableRow.getLayoutParams().WRAP_CONTENT, tableRow.getLayoutParams().WRAP_CONTENT)); 
+2

Вы можете сделать две вещи .. 1) написать макет в XML и установить видимость на основе при условии 2) Добавить макет динамически на основе условия – ashutiwari4

ответ

0

Вам нужен гибкий интерфейс, где вы можете заменить фрагменты на основе необходимого условия, вы не можете достичь этого, просто используя xml-дизайн, вам также придется использовать базовые функции java.

Чтобы динамически заменить фрагмент, который вы должны будете

// Create fragment and give it an argument specifying the article it should show 
ArticleFragment newFragment = new ArticleFragment(); 
Bundle args = new Bundle(); 
args.putInt(ArticleFragment.ARG_POSITION, position); 
newFragment.setArguments(args); 

FragmentTransaction transaction  getSupportFragmentManager().beginTransaction(); 

// Replace whatever is in the fragment_container view with this fragment, 
// and add the transaction to the back stack so the user can navigate back 
transaction.replace(R.id.fragment_container, newFragment); 
transaction.addToBackStack(null); 

// Commit the transaction 
transaction.commit(); 

Вы можете обратиться к документации flexible UI design here

+0

Спасибо, я попробую это ... –