视图布局未按预期显示

时间:2013-03-13 19:37:57

标签: c# android android-layout xamarin.android xamarin

我正处于松散状态。

问题:我将 GraphInWebView 扩展到名为formDialog(其他一些文件)的布局中 formDialog.AddView(LayoutInflater.Inflate(Resource.Layout.GraphInWebview, null));

单独这一点很完美,但是一旦我尝试将 LineItem 膨胀到 GraphInWebView @ + id / SideWidget ,后者永远不会得到了显示。

我检查了源代码 - LineItem 视图已膨胀,但只是没有嵌套在SideWidget中

我有以下xml文件。

GraphInWebview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  <WebView
      android:id="@+id/graphView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="#00FF00"/>
  <LinearLayout
        android:id="@+id/SideWidget"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#0000FF">
  </LinearLayout>
</LinearLayout>

lineItem.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
  <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
    <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/Icon"
      android:maxHeight="5dp"
      android:maxWidth="5dp"
      android:id="@+id/icon"
      android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"/>
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Appointment: Appointment with Spur Cresta"
      android:id="@+id/appointmentTitle"
      android:minWidth="60dp"
      android:layout_alignParentBottom="true"
      android:layout_toRightOf="@+id/icon"/>
  </RelativeLayout>
  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Appointment: Appointment with Spur Cresta"
    android:id="@+id/appointmentText"
    android:minWidth="60dp"/>
</LinearLayout>

C#

        //First inflate views to be injected into the default action bar
        formDialog.AddView(LayoutInflater.Inflate(Resource.Layout.googleGraphInWebview, null));

        manageScheduleButton = (Button)FindViewById(Resource.Id.ManageButton);
        locationalServicesButton = (Button)FindViewById(Resource.Id.LocationalServicesButton);
        myProfileButton = (Button)FindViewById(Resource.Id.MyProfileButton);
        myClientsButton = (Button)FindViewById(Resource.Id.MyClientsButton);

        manageScheduleButton.Click += ManageScheduleMenuClick;
        locationalServicesButton.Click += locationalServicesButtonClick;
        myProfileButton.Click += myProfileButtonClick;
        myClientsButton.Click += myClientsButtonClick;

        formDialog.SetMinimumHeight(400);

        WebView graph = FindViewById<WebView>(Resource.Id.graphView);
        LinearLayout sideWidget = FindViewById<LinearLayout>(Resource.Id.SideWidget);
        sideWidget.AddView(LayoutInflater.Inflate(Resource.Layout.LineItem, null));

        graph.Settings.JavaScriptEnabled = true;
        graph.SetWebViewClient(new webView(formDialog));
        graph.LoadUrl("file:///android_asset/graph.html");

有人可以建议解决这个问题的方法吗?

问候

A

1 个答案:

答案 0 :(得分:0)

我想通了......机器人的layout_weight是关键......

鉴于两个布局都请求的视图,例如fill_parent,例如,希望他们共享视图40 - 60,您将分配给一个layout_weight=4和另一个layout_weight=6 {1}}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  <WebView
      android:id="@+id/graphView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="#00FF00"/>
  <LinearLayout
        android:id="@+id/SideWidget"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#0000FF">
  </LinearLayout>
</LinearLayout>

我发布完成的代码

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
      <WebView
          android:id="@+id/graphView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_wight="2"
            android:background="#00FF00"/>
      <LinearLayout
        android:id="@+id/SideWidget"
        android:orientation="vertical"
        android:layout_wight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#0000FF">
  </LinearLayout>
</LinearLayout>