0

Helo every one, i try to open fragment in FrameLayout, but the screen is white. My code is:

public class ProfileActivity extends FragmentActivity {
Database db;
TextView tvName, tvCity;
ImageView imageView;
private FragmentTabHost mTabHost;
FrameLayout frameLayout;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    frameLayout = (FrameLayout) findViewById(R.id.frame_layout);
    initialize();
}

private void initialize() {
    tvName = (TextView) findViewById(R.id.tv_name);
    tvCity = (TextView) findViewById(R.id.tv_city);
    db = Database.getInstance(this);
    imageView = (ImageView) findViewById(R.id.iv_profile);
    Fragment fragment = new StatisticFragment();
    FragmentTransaction transaction = getSupportFragmentManager()
            .beginTransaction();
    transaction.replace(R.id.frame_layout, fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}
}

activity_profile.xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent" android:background="#ffffff">
<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp" android:layout_weight="1">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="fill_parent" android:layout_weight="1">
        <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/iv_profile" android:src="@drawable/background_profile_first_part"
                android:scaleType="fitXY"/>
    </LinearLayout>
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="fill_parent" android:layout_weight="1.4"
            android:background="@drawable/background_profile_second_part">
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="New Text"
                android:id="@+id/tv_name" android:layout_gravity="right|center_vertical"
                android:textColor="#ffffff"/>
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="New Text"
                android:id="@+id/tv_city" android:layout_gravity="center"/>
        <LinearLayout
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
            <android.support.v4.app.FragmentTabHost
                    android:id="@android:id/tabhost"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    >
                <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:visibility="invisible"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        />
            </android.support.v4.app.FragmentTabHost>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

    <FrameLayout
            android:id="@+id/frame_layout"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="2">
    </FrameLayout>
 </LinearLayout>

StaticFragment.class

public class StatisticFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_statistic, null);
    return v;
}
}

fragment_statistic.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
<TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Statistic"
        android:id="@+id/textView" android:layout_gravity="left|center_vertical"      android:textColor="#fff555"/>
   </LinearLayout>
Kostya Khuta
  • 673
  • 2
  • 7
  • 21
  • Try just edit your layout - put your `statistic.xml` contents inside `activity.xml` instead of `FrameLayout`. My guess is that the problem is with your layout. – agamov Mar 31 '14 at 06:24
  • You do not have a single root viewgroup in the activity.xml. Try wrapping a RelativeLayout around both your top LinearLayout and the FrameLayout. – mach Mar 31 '14 at 06:27
  • @mach, no i have the root element – Kostya Khuta Mar 31 '14 at 06:34

2 Answers2

0

Apply a background to the linear layout in the statistic fragment xml

Aditya_Anand
  • 525
  • 7
  • 17
0
I think you have set visibility to invisible inside frame layout so please edit your layout file
from 

<android.support.v4.app.FragmentTabHost
                    android:id="@android:id/tabhost"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    >
                <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:visibility="invisible"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        />
            </android.support.v4.app.FragmentTabHost>


remove this line and try again.

android:visibility="invisible"
gandhi
  • 122
  • 6