简体   繁体   中英

Android : Using layoutinflater for custom layout dynamically

I am doing a videoconference APP where I have a framelayout which will have surfaceview to render video and Button to end that participant call.

since the participants can be added dynamically I have to inflate this layout when ever request comes to create a new user.

this inflated layout will be added into tablelayout so that I can accommodate many layouts / users in which ever order I want.

I am inflating the FrameLayout like :

participantHolder.mParticipantFrameLayout = (FrameLayout)mInflater.inflate(R.layout.generic_paritcipant_layout, null);

and I am getting the surface view button inside this layout using :

//get the Dropuser button
participantHolder.mParticipantDropButton = (ImageButton)mFrameLayt.findViewById(R.id.ParticipantDropButton);
//get the surfaceview
participantHolder.mParticipantSurfaceView = (SurfaceView)mFrameLayt.findViewById(R.id.ParticipantSurfaceView);

and adding the layout into table row by setting the layout params.

TableRow.LayoutParams PreviewLayoutParams = new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT);
PreviewLayoutParams.weight = 1;
CurrentParticpant.mParticipantUIHolder.mParticipantFrameLayout.setLayoutParams(PreviewLayoutParams);
CurrentParticpant.mParticipantUIHolder.mParticipantFrameLayout.invalidate();
mTableRowOne.addView(CurrentParticpant.mParticipantUIHolder.mParticipantFrameLayout);
mTableRowOne.invalidate();
mTableLayoutReference.invalidate();

But I am not able to see the View/Layout at all please let me if am doing some thing wrong

I assume the problem is here:

TableRow.LayoutParams PreviewLayoutParams = new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT);

First argument means width and you set it to 0. Please try the following:

TableRow.LayoutParams PreviewLayoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT, 1);

Using such constructor you don't need to add PreviewLayoutParams.weight = 1; http://developer.android.com/reference/android/widget/TableRow.LayoutParams.html#TableRow.LayoutParams%28int,%20int,%20float%29

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM