2012-10-18 34 views
1

我有一个非常简单的布局:为什么这个布局没有膨胀到全宽?

<?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> 

我夸大它像这样:

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); 

而且我这是怎么表现出来:

public void showIt(final Device device) { 
    //first create the DialogFragment to show the progress 
    theDialog = theDialog 
     .newInstance(); 

    theDialog.show(getSupportFragmentManager(), 
     "dialog"); 

    getSupportFragmentManager().executePendingTransactions(); 
    } 

片段比较狭窄 - 约三分之一的屏幕宽度,即使我明确有“match_parent”

奇怪的是,Android 2.1上的老式Android手机几乎将屏幕宽度膨胀 - 而在所有其他运行Android 4+的手机上,它都很窄。

我检查了容器的值,它在任何情况下都是null。 (不应该是父母吗?)

Sherlock会有问题吗?

我甚至明确地将宽度设置为1000dp,但新的片段仍然很窄。 同时更改为LinearLayout并没有帮助。

任何想法可能是什么原因呢?

我得到这个更广泛的唯一方法是在所有地方设置特定的宽度像“500dp”!在这个xml文件中。 非常感谢!

+0

你的主机活动看起来如何?你如何添加片段? –

+0

您正在替换或添加片段的容器的宽度可能较小 –

+0

@ Rolf Smit请参阅我的编辑 - 我只是实例化它,并且主机活动填充完整宽度 – user387184

回答

0

我已经体会到一些属性可以覆盖layout_width-attribute。尝试从您的RelativeLayout中移除layout_centerHorizo​​ntal,layout_centerVertical和scaleType。据我所知,他们无论如何都没有任何目的。

+0

谢谢,我删除了它们 - 但不幸的是它没有改变任何东西... – user387184

+1

那为什么让它成为答案? –