-1

I want the image in the left side and the switch text in middle and switch button in right corner. Here is my code

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_mobile_data_usage"
        android:layout_marginStart="10dp"
        />

    <android.support.v7.widget.SwitchCompat
        android:id="@+id/switch_compat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="Mobile Data"
        android:textAlignment="center"
        android:textOff=""
        android:textOn=""
        app:showText="true" />

</LinearLayout>
4

5 回答 5

0

像这样试试

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_mobile_data_usage"
            android:layout_marginStart="10dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="switchText"
        android:layout_centerHorizontal="true"/>

        <android.support.v7.widget.SwitchCompat
            android:id="@+id/switch_compat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:layout_gravity="right"
            android:text="Mobile Data"
            android:layout_alignParentRight="true"
            android:textOff=""
            android:textOn=""
            app:showText="true" />

</RelativeLayout>
于 2017-04-20T10:22:30.480 回答
0

干得好。我想这就是你想要的。

<LinearLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

<ImageView
       android:layout_width="0dp"
       android:layout_weight="1"
       android:layout_height="wrap_content"
       android:src="@drawable/ic_mobile_data_usage"
       android:scaleType="fitStart"
       android:layout_marginStart="10dp" />

<android.support.v7.widget.SwitchCompat
       android:layout_width="0dp"
       android:layout_weight="1"
       android:layout_height="wrap_content"
       android:checked="false"
       android:text="Mobile Data"
       android:layout_gravity="center_vertical"
       android:textAlignment="center"
       android:textOff=""
       android:textOn=""
       app:showText="true"/>
</LinearLayout>
于 2017-04-20T10:18:09.710 回答
0

试试这个也许:

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="hoizontal" 
>
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_mobile_data_usage"
    android:layout_marginStart="10dp"
    />

<TextView
    android:id="@+id/switch_tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Mobile Data"
    android:textAlignment="center"
    />

<Switch
   android:id="@+id/switch"
   android:layout:width="wrap_content"
   android:layout:height="wrap_content"
   android:gravity="right|top"
   android:checked="false"/>

</LinearLayout>

如果要在 LinearLayout 中进行静态定位

  android:weightSum="100"

在你的物品中

  android:layout_width="0dp"
  abdroid:layout:weight="40" 

如果您希望您的项目的尺寸为宽度的 40%,请使用 40 作为重量,33% 使用 33 作为重量,并且它会按照您的意愿排列 :)

可以通过开关的变化来改变文本。 Android 如何正确获取 Switch 的值?

制造

于 2017-04-20T10:24:38.370 回答
0
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_weight="1"
            android:src="@drawable/ic_mobile_data_usage"
            android:layout_marginStart="10dp"
            />

        <android.support.v7.widget.SwitchCompat
            android:id="@+id/switch_compat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="false"
            android:text="Mobile Data"
            android:layout_gravity="center"
            android:textAlignment="center"
            android:textOff=""
            android:textOn=""
            app:showText="true" />

    </LinearLayout>

尝试这种方式使您的图像大小修复

于 2017-04-20T10:12:39.327 回答
0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_mobile_data_usage"
    android:layout_gravity="center"
    android:layout_marginStart="10dp"/>


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:gravity="center"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:text="Mobile Data" />

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:checked="false"
    android:textOff=""
    android:textOn=""
/>


</LinearLayout> 

试试这个实现

于 2017-04-20T10:52:28.023 回答