2015-03-25 43 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,直到视图被重新创建。

相关问题