Layout_weight and Fragment

Hi,
I have small application with ActionBar. On tab select I switch view using code below:

ContactFragment fragment = new ContactFragment();
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.fragmentContainer, fragment).Commit();

Contact fragment is also simple:
public class ContactFragment : Fragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.Contact, container, false);
v.LayoutParameters = new ViewGroup.LayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));

    return v;
}

}

And Contact .axml layout

<?xml version="1.0" encoding="utf-8"?>



The problem is that Contact View is blank - when I put the same view for a splash screen it works ok (half red / half green). I can use static dp values instead 0dp and layout_weight but this is not a solution. Is there any way to make layout_weight works in inflated View?

Posts

  • DariuszSrokaDariuszSroka PLMember ✭✭

    Formatting is messed up.. i copied code to pastebin.com/4cCryjbf

  • CheesebaronCheesebaron DKInsider, University mod

    Paste your code here, mark it, and press the "C" button

  • DariuszSrokaDariuszSroka PLMember ✭✭
    public void OnTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
    {
            DisplayContactFragment(tab);
    }
    
    private void DisplayContactFragment(ActionBar.Tab tab)
    {
            ContactFragment fragment = new ContactFragment();
            SupportFragmentManager.BeginTransaction().Replace(Resource.Id.fragmentContainer, fragment).Commit();
    }
    
    -------------------------------------
    
        public class ContactFragment : Fragment
        {        
            public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            {
                View v = inflater.Inflate(Resource.Layout.Contact, container, false);
                v.LayoutParameters = new ViewGroup.LayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));
            }
    
    -------------------------------------
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="fill_parent"
      android:fillViewport="true"
            android:layout_height="fill_parent">
      <LinearLayout android:background="#FF0000"
                    android:layout_height="0dp" android:layout_width="fill_parent"
                    android:layout_weight="1" />
      <LinearLayout android:background="#00FF00"
                    android:layout_height="0dp" android:layout_width="fill_parent"
                    android:layout_weight="1" />
    </LinearLayout>
    
  • DariuszSrokaDariuszSroka PLMember ✭✭

    any solutions?

Sign In or Register to comment.