Using relativelayout to add controls side by side to take the whole width of the screen

StackOverflow https://stackoverflow.com/questions/22449152

  •  15-06-2023
  •  | 
  •  

質問

Android Studio 0.5.1

Hello,

The screenshot I have put in a layout_width of 200dp. But not a good solution as this will be too much or too small on the screen size. I would like to fit both so that the seekbar will only take up as much room as need to fit the textview in at the end. enter image description here

Is it possible to use relativelayout to have controls side by side where the seekbar will take just enough room without overlapping the control to the right of it (TextView)?

I would like the seekbar and textview to take the whole of the width together.

For the seekbar I have used match parent. However, this has pushed the textview out of sight.

I would like the seekbar to stop where the textview starts. I don't want to use dp on the layout_width as each device is different.

I don't want to switch to linear layout as I have other controls that are using this layout (not shown here).

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  <SeekBar
        android:id="@+id/sbSensitivity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="15"
    android:layout_alignParentLeft="true"/>

    <TextView
        android:id="@+id/tvSensitivityDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="22sp"
        android:text="15"
        android:layout_toRightOf="@+id/sbSensitivity"
    android:layout_alignParentRight="true"/>

</RelativeLayout>

I hope you understand what I mean?

Many thanks for any suggetions,

役に立ちましたか?

解決

Try this

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
 <SeekBar
        android:id="@+id/sbSensitivity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:max="15"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/tvSensitivityDisplay"/>

    <TextView
        android:id="@+id/tvSensitivityDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="22sp"
        android:text="15"
    android:layout_alignParentRight="true"/>

</RelativeLayout>

他のヒント

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" android:weightSum="2">

  <SeekBar
        android:id="@+id/sbSensitivity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="15"
       android:layout_weight="1"        
    />

    <TextView
        android:id="@+id/tvSensitivityDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="22sp"
      android:layout_weight="1"       
       android:text="15"
     />
</LinearLayout>
</RelativeLayout>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top