Android partial layout alternative implementations

  Recently re-engage in remote video function, in which to achieve load video, load the video fails to load successfully replace the local layout, access to relevant information, find an opportunistic way.

  First, write each child layout of these three effects, respectively

top_remotetreate.xml,
top_attemptconnect.xml,
top_failcon.xml 

then include three main layout xml, as follows:
<include
android:id="@+id/inc_remotetreate"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
layout="@layout/top_remotetreate" />

<include
android:id="@+id/inc_attemptconnect"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:visibility="gone"
layout="@layout/top_attemptconnect" />

<include
android:id="@+id/inc_failconnect"
Android: layout_width = "match_parent"
Android: layout_height = "240dp"
Android: layout_marginTop = "10DP"
Android: layout_marginRight = "10DP"
Android: layout_marginLeft = "10DP"
Android: visibility = "Gone"
layout = "@ layout / top_failcon" />
That is a temporary display, and the other two are hidden (three states visibility attribute Android in control: visible (visible), invisible (invisible), hidden (gone)
Finally Gets layout object in the corresponding Java file , set its Visibility property:
private LinearLayout inc_remotetreate,inc_attemptconnect,inc_failconnect;
inc_remotetreate = view.findViewById(R.id.inc_remotetreate);
inc_attemptconnect = view.findViewById(R.id.inc_attemptconnect);

inc_failconnect = view.findViewById(R.id.inc_failconnect);
inc_remotetreate.setVisibility(View.GONE);

inc_attemptconnect.setVisibility(View.VISIBLE);
inc_failconnect .setVisibility (View.GONE); 
thus achieving the desired effect achieved yo! ! !
 

Guess you like

Origin www.cnblogs.com/dmrbell/p/11286699.html