I have a chart.xml and I am setting a background chart in it in a ViewPager using
android:background="@drawable/chart_bg".
The problem is:
xml view is showing the chart_bg when I see it's layout mode but when I start/run the application the background chart chart_bg is not seen in the real device.
chart.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chartmain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="1dp"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal" >
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Fri Jul 13, 2012"
/>
</LinearLayout>
<RelativeLayout
android:id="@+id/relative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<android.support.v4.view.ViewPager
android:id="@+id/HView"
android:layout_width="360dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:background="@drawable/chart_bg">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Java File:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle bundle = getArguments();
view = inflater.inflate(R.layout.chart, container, false);
return view;
}
Finally resolved by explictly setting background image in code like this:
private ViewPager mPager;
mPager = (ViewPager) view.findViewById(R.id.HView);
mPager.setBackgroundResource(R.drawable.chart_bg);
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With