I have a quite simple layout:
<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/b"
android:scaleType="fitXY" >
<ProgressBar
android:id="@+id/progressD"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:progress="0" />
<TextView
android:id="@+id/numberO"
style="@android:style/TextAppearance.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/progressD"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
And I inflate it like this:
public class MyFragment extends
SherlockDialogFragment {
static MyFragment newInstance() {
MyFragment theDialog = new MyFragment();
return theDialog;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(
R.layout.dialog_show_progress_during_connection_test,
container, false);
And this is how I show it:
public void showIt(final Device device) {
//first create the DialogFragment to show the progress
theDialog = theDialog
.newInstance();
theDialog.show(getSupportFragmentManager(),
"dialog");
getSupportFragmentManager().executePendingTransactions();
}
The fragment is rather narrow – about 1/3 of the screen width, even though I explicitly have “match_parent”
Curiously on an old Android phone with Android 2.1 it inflates almost to the width of the screen – while on all others running Android 4+ it is narrow.
I checked the value of container, it is null in all cases. (shouldn’t it be the parent ?)
Could there be an issue with Sherlock?
I even set the width explicitly to 1000dp, but the new fragment remains narrow.
Also changing to LinearLayout does not help.
Any ideas what could be the reason for this?
The only way I got this to become wider was to set specific width like “500dp” in all places! within this xml file.
Many thanks!
I have experienced that some attributes can override the layout_width-attribute. Try to remove layout_centerHorizontal, layout_centerVertical and scaleType from your RelativeLayout. As far as I can see, they fill no purpose either way.