我面临一个奇怪的问题,对话框片段,它没有显示完整的正确布局。我检查了Moto G和Nexus 5都显示了相同的结果。任何帮助将不胜感激。
图形布局屏幕截图是:
设备屏幕截图是:
以下是活动代码:
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showGridTutorial();
}
public void showGridTutorial() {
DialogFragment fragment = new GridTutorial();
fragment.show(getSupportFragmentManager(), "grid_tutorial");
}
public static class GridTutorial extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_layout);
return dialog;
}
}
}
XML布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#eeede9"
>
<View
android:id="@+id/vertical"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_above="@+id/btnGotIt"
android:background="#e8e7e4"
/>
<View
android:id="@+id/horizontal"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:background="#e8e7e4" />
<Button
android:id="@+id/btnGotIt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Got it"
android:gravity="center"
android:background="@android:color/black"
android:textColor="#eeede9"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/vertical"
android:layout_above="@+id/horizontal"
android:src="@drawable/showease3" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/vertical"
android:layout_above="@+id/horizontal"
android:src="@drawable/showdase" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/horizontal"
android:layout_toLeftOf="@+id/vertical"
android:layout_above="@+id/btnGotIt"
android:src="@drawable/showcase" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/horizontal"
android:layout_toRightOf="@+id/vertical"
android:layout_above="@+id/btnGotIt"
android:src="@drawable/showdase" />
</RelativeLayout>
答案 0 :(得分:0)
尝试将RelativeLayout宽度和高度更改为wrap_content。
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eeede9"
希望这会对你有帮助!
答案 1 :(得分:0)
您需要为布局选择最小宽度和最小高度。类似的东西:
var x = XDocument.Parse("<x xml:space='preserve'>
\r\n</x>");
present("content", x.Root.Value); // 13 10, expected
present("formatted", toString(x)); // inside <x/>: 38 35 120 68 59 10 ("
\n"), acceptable
x = XDocument.Parse(toString(x));
present("round tripped", x.Root.Value); // 13 10, expected
string toString(XDocument xd)
{
using (var sw = new StringWriter())
{
using (var writer = XmlWriter.Create(
sw,
new XmlWriterSettings
{
NewLineHandling = NewLineHandling.Entitize,
}))
{
xd.WriteTo(writer);
}
return sw.ToString();
}
}
void present(string label, string thing)
{
Console.WriteLine(label);
Console.WriteLine(thing);
Console.WriteLine(string.Join(" ", Encoding.UTF8.GetBytes(thing)));
Console.WriteLine();
}
尝试使用正确的值。