如何创建?我试过了。我知道实现目标的正确方法是什么? 我想创造这个。
Textview In center
Seek Bar TextView
" TextView
" TextView
" TextView
" TextView
这是我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/description"
android:textSize="30sp"
android:layout_marginTop="50dp"
android:gravity="center_horizontal"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<com.example.androidtesting.VerticalSeekBar
android:id="@+id/verticalSeekbar"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:max="100"
android:progress="5"
android:progressDrawable="@drawable/progress"
android:thumb="@drawable/thumb"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fivemore"
android:textSize="25sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/threetofour"
android:textSize="25sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/onetotwo"
android:textSize="25sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/onceamonth"
android:textSize="25sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/specialevents"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:1)
我试图了解你的结构,我认为你并不是很遥远。我做了一些修改并对其进行了评论:
<?xml version="1.0" encoding="utf-8"?>
<!-- RelativeLayout instead of LinearLayout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- set id + align parent top to true -->
<TextView
android:id="@+id/text_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="@string/description"
android:textSize="30sp"
android:layout_marginTop="50dp"
android:gravity="center_horizontal"
android:textStyle="bold" />
<!-- below the id text_header + weightSum to 1 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/text_header"
android:orientation="horizontal"
android:baselineAligned="false"
android:weigthSum="1" >
<!-- layout weight to 0.5 + width to 0 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"
android:orientation="vertical" >
<com.example.androidtesting.VerticalSeekBar
android:id="@+id/verticalSeekbar"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:max="100"
android:progress="5"
android:progressDrawable="@drawable/progress"
android:thumb="@drawable/thumb" />
</LinearLayout>
<!-- layout weight to 0.5 + width to 0 + weightSum to 5 -->
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical"
android:weightSum="5" >
<!-- layout weight to 1 + height to 0 + text center vertical -->
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/fivemore"
android:textSize="25sp"
android:gravity="center_vertical" />
<!-- same as above... -->
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/threetofour"
android:textSize="25sp"
android:gravity="center_vertical" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/onetotwo"
android:textSize="25sp"
android:gravity="center_vertical" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/onceamonth"
android:textSize="25sp"
android:gravity="center_vertical" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/specialevents"
android:textSize="25sp"
android:gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
我不确定,但这会给你预期的行为。如果这有帮助,请告诉我。
答案 1 :(得分:0)
您可以尝试这样的事情:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10sp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Text in center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Right side" />
</LinearLayout>
</LinearLayout>