Android 关于用户界面的问题
看看我截图上的图片,我用它来陈述我的问题 以下是我的布局代码:Android 关于用户界面的问题,android,android-layout-weight,Android,Android Layout Weight,看看我截图上的图片,我用它来陈述我的问题 以下是我的布局代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="cente
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="@drawable/hexun_dh6"
android:gravity="center_vertical"
android:text="你好" />
<TextView
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="@drawable/hexun_dh6"
android:gravity="center_vertical"
android:text="你好" />
<TextView
android:id="@+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="@drawable/hexun_dh6"
android:gravity="center_vertical"
android:text="你好" />
<TextView
android:id="@+id/four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="@drawable/hexun_dh6"
android:gravity="center_vertical"
android:text="你好" />
布局结果如上图所示,我的疑问是为什么文字远离可绘制,我想知道结果:
我尝试将drawablepadding设置为小于零,但它不起作用,我该怎么做,我只想使用这种方式,不想使用
TextView
和ImageView
,感谢高级。这里是另一个黑客解决方案。试试这个:)
诀窍在于,将不可见视图放在文本视图之间,文本视图将简单地将内容作为宽度进行换行
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<TextView
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/big_star_orange"
android:gravity="center"
android:text="你好" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<TextView
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/big_star_orange"
android:gravity="center"
android:text="你好" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<TextView
android:id="@+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/big_star_orange"
android:gravity="center"
android:text="你好" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<TextView
android:id="@+id/four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/big_star_orange"
android:gravity="center"
android:text="你好" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
</LinearLayout>
之后就不需要重力了,只需要重心。希望有帮助
android:gravity=“center”
用于对齐文本视图中心,而android:gravity=“center | right”用于对齐文本视图右侧。