Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android layout Android布局是否要占用所有可用空间?_Android Layout_Xamarin_Xamarin.android_Fluid Layout_Stretch - Fatal编程技术网

Android layout Android布局是否要占用所有可用空间?

Android layout Android布局是否要占用所有可用空间?,android-layout,xamarin,xamarin.android,fluid-layout,stretch,Android Layout,Xamarin,Xamarin.android,Fluid Layout,Stretch,请帮助我实现这个布局,我需要3个ImageView和一个TextView在同一行中,最后两个对齐到右侧。我试过把它们放在线性布局、网格布局、表格布局、相对布局中,但看在上帝的份上,我想不出来 谢谢大家! 线性布局(比例): 它们之间有什么比例吗?嗨,我已经看到了你的代码,并更新了我的答案,请测试一下。非常感谢,这个位置非常完美!唯一的问题是,imageView2位于最右边的位置,而不是imageView3。我有一个受过教育的猜测,为什么会发生这种情况,但我想知道你的解决方案,如果可能的话!非常感

请帮助我实现这个布局,我需要3个ImageView和一个TextView在同一行中,最后两个对齐到右侧。我试过把它们放在线性布局、网格布局、表格布局、相对布局中,但看在上帝的份上,我想不出来

谢谢大家!

线性布局(比例):
它们之间有什么比例吗?嗨,我已经看到了你的代码,并更新了我的答案,请测试一下。非常感谢,这个位置非常完美!唯一的问题是,imageView2位于最右边的位置,而不是imageView3。我有一个受过教育的猜测,为什么会发生这种情况,但我想知道你的解决方案,如果可能的话!非常感谢。您好,通过
得知imageView2位于最正确的位置,而不是imageView3
,我不明白,您能展示一张图片吗?谢谢是的,很抱歉,现在是这样:非常抱歉,我忘了提到我需要通过编程实现此功能,这是我到目前为止所做的,遵循您的xml:
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:layout_margin="5dp"
        android:src="@drawable/ic_launcher_background"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp" />
    <TextView
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:text="TextView"
        android:gravity="center"
        android:layout_width="0dp"
        android:layout_weight="2"
        android:layout_height="50dp"
        android:background="@color/colorAccent"/>
    <View
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp"/>
    <ImageView
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:src="@drawable/ic_launcher_background"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp" />
    <ImageView
        android:layout_margin="5dp"
        android:src="@drawable/ic_launcher_background"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp" />
</LinearLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_margin="5dp"
        android:id="@+id/iv1"
        android:src="@drawable/ic_launcher_background"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <TextView
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_toRightOf="@id/iv1"
        android:id="@+id/tv"
        android:text="TextView"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@color/colorAccent"/>
    <ImageView
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_toLeftOf="@id/iv3"
        android:id="@+id/iv2"
        android:src="@drawable/ic_launcher_background"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <ImageView
        android:layout_margin="5dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:id="@+id/iv3"
        android:src="@drawable/ic_launcher_background"
        android:layout_width="50dp"
        android:layout_height="50dp" />
</RelativeLayout>
        var relativeLayout = new Android.Widget.RelativeLayout(this)
        {
            LayoutParameters = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent),
            LayoutDirection = LayoutDirection.Ltr
        };

        var imageView1 = new ImageView(this);
        imageView1.SetImageResource(Resource.Drawable.icon);
        var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
        layoutParams.SetMargins(5, 5, 5, 5);
        imageView1.Id = 1;
        imageView1.LayoutParameters = layoutParams;
        relativeLayout.AddView(imageView1);


        View childView1 = relativeLayout.GetChildAt(0);
        var textView = new TextView(this)
        {
            Text = "TextView"
        };
        layoutParams = new Android.Widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
        layoutParams.AddRule(LayoutRules.RightOf, childView1.Id);
        layoutParams.SetMargins(0, 5, 5, 5);
        textView.Id = 2;
        textView.LayoutParameters = layoutParams;
        relativeLayout.AddView(textView);

        var imageView3 = new ImageView(this);
        imageView3.SetImageResource(Resource.Drawable.icon);
        layoutParams = new Android.Widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
        layoutParams.AddRule(LayoutRules.AlignParentEnd);
        layoutParams.AddRule(LayoutRules.AlignParentRight);
        imageView3.Id = 3;
        imageView3.LayoutParameters = layoutParams;
        relativeLayout.AddView(imageView3);

        View childView2 = relativeLayout.GetChildAt(2);
        var imageView2 = new ImageView(this);
        imageView2.SetImageResource(Resource.Drawable.icon);
        layoutParams = new Android.Widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
        layoutParams.AddRule(LayoutRules.LeftOf, childView2.Id);
        imageView2.Id = 4;
        imageView2.LayoutParameters = layoutParams;
        relativeLayout.AddView(imageView2);