我有一个非常简单的布局:为什么这个布局没有膨胀到全宽?
<?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文件中。 非常感谢!
你的主机活动看起来如何?你如何添加片段? –
您正在替换或添加片段的容器的宽度可能较小 –
@ Rolf Smit请参阅我的编辑 - 我只是实例化它,并且主机活动填充完整宽度 – user387184