简体   繁体   English

如何在android中创建两个固定大小的视图和一个跨越它们的视图?

[英]how to create two fixed size views and one view spanned between them in android?

I want to create a screen 我想创建一个屏幕

with two fixed size areas: one aligned to left, one to the right 具有两个固定大小的区域:一个区域向左对齐,一个区域向右对齐

and in between them another area which spans all the rest of the area? 在它们之间的另一个区域跨越了所有其他区域?

If I make the middle view with property fill_parent it will catch all the area to the 3rd child. 如果我使用属性fill_parent进行中间视图,它将捕获到第三个孩子的所有区域。

what will be the effective property when layout_weight=0.X and layout_width=20dp .? layout_weight=0.Xlayout_width=20dp时,有效属性是什么?

====== ======

I have a linearLayout with orientation= horizontal . 我有一个direction orientation= horizontal的linearLayout。

It has a child with layout_weight=0.X and also layout_width=20dp . 它有一个layout_weight=0.X的孩子,还有layout_width=20dp

What will be the effective property? 什么是有效财产?

If you have a horizontal LinearLayout with the first child with a fixed width (eg layout_width="20dp" ), the second child with a non-zero weight (eg layout_weight="1" ) and the third with a fixed width (eg layout_width="20dp" ), then you should get the first aligned to the left, the third aligned to the right and the third filling the area between them. 如果您具有水平LinearLayout ,并且第一个子级具有固定的宽度(例如, layout_width="20dp" ),第二个子级具有非零的权重(例如, layout_weight="1" ),而第三个子级具有固定的宽度(例如, layout_width="20dp" ),那么您应该使第一个与左侧对齐,第三个与右侧对齐,第三个填充它们之间的区域。

It's also possible to do this with a RelativeLayout , but I'll leave that as the above solution should work just fine. 也可以使用RelativeLayout做到这一点,但我将保留上述内容,因为上述解决方案应该可以正常工作。

It will be something like this: 将会是这样的:

<LinearLayout android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="horizontal">

     <View android:id="@+id/view1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"/>

     <View android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"/>

     <View android:id="@+id/view3"
           android:layout_width="20dp"
           android:layout_height="wrap_content"
           android:layout_weight="0"/>

</LinearLayout>

You should use android:layout_weight . 您应该使用android:layout_weight

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建一个将两个视图结合在一起的视图类 - Create a view class that is a combination of two views Android 如何在Android中的文本视图上设置多个跨文本 - how to set multiple spanned with text on text view in android 如何在Android中创建固定大小的图像文件? - How to create an image file with fixed size in Android? 我有两个水平滚动视图。 如何一次显示一个,并在单击按钮时在它们之间切换? - I have two horizontal scroll views. How can I show one at a time and switch between them on button click? 如何多人同时加入同一个频道,让我们在 Agora Android 中有两个远程视图和一个本地视图? - How multiple people can join the same channel so that we have two remote views and one local view in Agora Android? 如何在两个Android应用程序之间创建交互 - How to create interaction between two android applications 具有两个Text视图的Android可扩展列表视图 - Android expandable list view with two Text views 如何检测视图之间的滑动以在android java中穿过它们? - How to detect swipe between views to make path across them in android java? GWT使用一个Presenter创建两个视图 - GWT create two Views used one Presenter 如何在Android中添加卡片视图列表,并且只能通过滑动将其中一个视图移除? - How to add a list of card views in Android with only one of them removable by swiping?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM