Xamarin Android RelativeLayout设计器设置
我试着创建一个ListView项目布局,并适合左侧的图标,中间是主要文本,然后再分成两个文本(主文本高度的顶部和底部) )在主要文本的右侧 - 但我似乎无法使其“适合”取决于屏幕大小和文本。Xamarin Android RelativeLayout设计器设置
我的继承人目前AXML布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@android:color/darker_gray"
android:id="@+id/photoImageView" />
<TextView
android:text="App Name And UID"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textAlignment="viewStart"
android:background="@android:color/holo_blue_light"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_toRightOf="@id/photoImageView"
android:id="@+id/nameTextView" />
<TextView
android:text="Down: 723B/s"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textAlignment="viewStart"
android:background="@android:color/holo_blue_dark"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_toRightOf="@id/nameTextView"
android:id="@+id/downloadTextView" />
<TextView
android:text="Up: 2104MB/ss"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textAlignment="viewStart"
android:background="@android:color/holo_blue_dark"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_toRightOf="@id/nameTextView"
android:layout_below="@id/downloadTextView"
android:id="@+id/uploadTextView" />
有没有人有一个解决方案或东西我在想念?请注意即时尝试避免布局嵌套
回答:
如果您的要求允许,您可以使用LinearLayout而不是RelativeLayout来实现。在上面的示例中,您可以使用layout_weight属性来指定大小,使其始终占用屏幕上的特定比例,在上面的示例中,我使用了1(应用图标) - 3(主文本) - 2(最后一部分)。这总共为6,这意味着无论屏幕大小如何,图标总是占用屏幕宽度的1/6,主文本将占用3/6,依此类推。查找代码执行本以下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minWidth="25dp"
android:minHeight="25dp">
<ImageView
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:background="@android:color/darker_gray"
android:id="@+id/photoImageView" />
<TextView
android:text="App Name And UID"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@android:color/holo_blue_light"
android:gravity="center_vertical"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="60dp"
android:id="@+id/nameTextView" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:text="Down: 723B/s"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="@android:color/holo_blue_dark"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:id="@+id/downloadTextView" />
<TextView
android:text="Up: 2104MB/ss"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="@android:color/holo_blue_dark"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:id="@+id/uploadTextView" />
</LinearLayout>
回答:
如果你只是想用一种布局,尝试GridLayout:
<GridLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:rowCount="2"
android:columnCount="6">
<ImageView
android:src="@drawable/rr"
android:layout_rowSpan="2"
android:background="@android:color/darker_gray"
android:id="@+id/photoImageView" />
<TextView
android:text="App Name And UID"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@android:color/holo_blue_light"
android:gravity="center_vertical"
android:layout_columnSpan="3"
android:layout_rowSpan="2"
android:layout_gravity="fill_vertical"
android:id="@+id/nameTextView" />
<TextView
android:text="Down: 723B/s"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="@android:color/holo_blue_dark"
android:gravity="center_vertical"
android:id="@+id/downloadTextView"
android:layout_gravity="fill"
android:layout_columnSpan="2" />
<TextView
android:text="Up: 2104MB/ss"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="@android:color/holo_blue_dark"
android:gravity="center_vertical"
android:id="@+id/uploadTextView"
android:layout_gravity="fill"
android:layout_columnSpan="2" />
</GridLayout>
以上是 Xamarin Android RelativeLayout设计器设置 的全部内容, 来源链接: utcz.com/qa/266920.html