2015-03-25 114 views
-1

我在我的xml佈局文件中添加了自定義視圖,即FancyCoverFlow。我想用視頻視圖在相同位置用程序代替這個視圖。意味着其他視圖的位置不應該改變。它應該顯示爲它在佈局文件中的位置。但只有我的自定義視圖應該替換爲具有FancyCoverFlow相同位置座標的視頻視圖。在android中動態替換另一個視圖的視圖?

<?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:id="@+id/layout" 
xmlns:fcf="http://schemas.android.com/apk/res-auto" 
android:background="@drawable/bga" 

android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Large Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceMedium" />  

<imageslideractivty.FancyCoverFlow 
    android:id="@+id/fancyCoverFlow" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"   
    fcf:maxRotation="45" 
    fcf:unselectedAlpha="0.3" 
    fcf:unselectedSaturation="0.0" 
    fcf:unselectedScale="0.4" 
    fcf:scaleDownGravity="0.5"/> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

<SeekBar 
    android:id="@+id/slider" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:layout_centerHorizontal="true" 
    android:progressDrawable="@null" 
    android:thumb="@drawable/middle" 
    android:layout_marginBottom="20dp" /> 
</LinearLayout> 

</LinearLayout> 

回答

5

現在,您可以切換從code..Use一個FrameLayout裏的知名度有像下面..

<?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:id="@+id/layout" 
xmlns:fcf="http://schemas.android.com/apk/res-auto" 
android:background="@drawable/bga" 

android:orientation="vertical"> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Large Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <VideoView 
     android:layout_width="match_parent" 
     android:visibility="invisible" 
     android:layout_height="match_parent" /> 


    <imageslideractivty.FancyCoverFlow 
     android:id="@+id/fancyCoverFlow" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:visibility="visible" 
     fcf:maxRotation="45" 
     fcf:unselectedAlpha="0.3" 
     fcf:unselectedSaturation="0.0" 
     fcf:unselectedScale="0.4" 
     fcf:scaleDownGravity="0.5" /> 

</FrameLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <SeekBar 
     android:id="@+id/slider" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:layout_centerHorizontal="true" 
     android:progressDrawable="@null" 
     android:thumb="@drawable/middle" 
     android:layout_marginBottom="20dp" /> 
</LinearLayout> 

2

爲此目的,您可以使用片段代替。把你的每個customViews放在Fragments中,然後用dynamically替換它。

5

假設你想顯示textView1但不是textView2一個按鈕的點擊事件中:

所以只要做到這一點:

textView1.setVisibility(View.VISIBLE); 
textView2.setVisibility(View.GONE); 

textview2會消失,如果你設置的LinearLayout WRAP_CONTENT的高度然後將下部持有

只是這樣做的textView1的部分與你的兩個觀點,即FancyCoverFlow和視頻查看

2

試試這個,

<?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:id="@+id/layout" 
xmlns:fcf="http://schemas.android.com/apk/res-auto" 
android:background="@drawable/bga" 

android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Large Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:textColor="#fff" 
    android:textAppearance="?android:attr/textAppearanceMedium" />  

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

<SeekBar 
    android:id="@+id/slider" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:layout_centerHorizontal="true" 
    android:progressDrawable="@null" 
    android:thumb="@drawable/middle" 
    android:layout_marginBottom="20dp" /> 
</LinearLayout> 

</LinearLayout> 

上述xml文件我已經添加的LinearLayout(linDynamic)你必須動態添加或替換你的FancyCoverFlow和videoview。

3

通常有一些方法可以通過另一種觀點認爲 方法1更換一個觀點:的意見 更改公開 前

textView1.setVisibility(View.VISIBLE); 
textView2.setVisibility(View.GONE); 

在這裏,你不刪除任何的意見,只是改變了知名度。

方法2: 您可以編程方式刪除該視圖的所有兒童,並添加新的意見 前。 你有一個LinewarLayout x;。和兩個孩子的意見TextView y, z;

現在你想通過一個又一個的TextView A. 更換Y,Z可以做到這一點像下面

x.removeAllViews(); 

and x.addView(A); 

在這裏你不能用X,Y,直到視圖被重新創建。

相關問題