【发布时间】:2015-07-17 17:11:50
【问题描述】:
在这段代码中,我需要将 Textview 的按钮向左对齐,我尝试使用everythnin ,使用相对布局、重力等......
我现在不知道为什么这仍然对齐到水平线的中心,我需要在左侧!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/dark_background"
android:orientation="vertical"
android:gravity="left" >
<ScrollView android:id="@+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:gravity="left"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dip"
>
<TextView
android:id="@+id/help_page_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/help_page_intro"
android:padding="2dip"
android:layout_weight="1"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="4dip"
android:layout_gravity="left"
>
<Button android:id="@+id/help_button1"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
style="@style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="@string/help_title_section1"
android:drawableTop="@drawable/help_image1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/help_text_section1"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button android:id="@+id/help_button2"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="@style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="@string/help_title_section2"
android:drawableTop="@drawable/help_image2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/help_text_section2"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentLeft="true">
<Button android:id="@+id/help_button3"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
style="@style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="@string/help_title_section3"
android:drawableTop="@drawable/help_image3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/help_text_section3"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left" >
<Button android:id="@+id/help_button4"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="@style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="@string/help_title_section4"
android:drawableTop="@drawable/help_image4"/>
<TextView
android:layout_width="wrap_content"
android:gravity="left"
android:layout_height="wrap_content"
android:text="@string/help_text_section4"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
【问题讨论】:
-
您想将按钮对齐在左侧,将 textview 对齐在右侧还是反之亦然?
-
我尝试使用您的 XML。您的所有视图都正确对齐到左侧。请把你的问题说清楚......你想让你的观点坚持到左边而不留任何空间吗?
-
有图片:help_button1,下一个是文字.....文字与中心水平对齐,但我需要help_button1和texview一起对齐左侧!
标签: android xml view-helpers