我从 android 开发开始,想知道如何使小部件准确适合我的 android Canvas 。这是图片。 我的目标是根据百分比填充小部件。
例如,第一个小部件 - TextView 的宽度和高度应为 50%。下一个小部件 - TextView 的宽度和高度应为 50%。
屏幕的下半部分——右侧应该有三个 TextView ——每个 TextView 应该有 1/3 的高度,高度应该是 50%。我该怎么做?
在底部,我想放置 slider 。这是 UI 设计的屏幕截图。

这是我糟糕的尝试。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.tune2wizard.modernartui.MainActivity" >
<TextView
android:id="@+id/textViewLabel"
android:layout_width="fill_parent"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="top|start"
android:background="#ff0000ff"
android:textColor="#ffffffff"
android:text="Modern Art UI" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/name">
<TextView
android:id="@+id/textFirstFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000ff"
android:textColor="#ffffffff"
android:text=" HELLO FIRST FIRST" />
</LinearLayout>
</RelativeLayout>
最佳答案
阅读“layout_weight”参数,您就会明白。我也是从 Coursera 开始的,祝你好运)
- http://developer.android.com/guide/topics/ui/layout/linear.html
- Android Layout Weight
- Linear Layout and weight in Android
- What does android:layout_weight mean?
对于边框检查“layout_margin”...
关于android - 如何在 Android 中以百分比形式为 TextView 设置布局文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30684896/