【发布时间】:2011-11-20 10:36:52
【问题描述】:
我正在尝试创建一个带有左右按钮的标题,中间有一个标题,按钮右侧有一个按钮(这将允许选择某些内容)。布局应该是这样的:
|<Button> <TextView><Button> <Button>|
如果标题很长,它应该是椭圆形的。为此,textview 似乎需要一个 layout_weight,如 this solution 中所示,否则它会将右侧按钮推离屏幕。但是,为 textview 设置 layout_weight 会将中心按钮推到右侧:
|<Button> <TextView> <Button><Button>|
目前的布局是这样的:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:text="Hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:text="Testing"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:singleLine="true"
android:layout_weight="1"
android:gravity="center"
android:ellipsize="end"
android:inputType="text"
/>
<Button
android:text="Hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="Hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
[编辑] 尝试 FunkTheMonk 的方法不太奏效,因为如果字符串很长,它最终会将中心按钮推出布局:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:text="Hello1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="1"
>
<TextView
android:text="Testing a very long text to see how it works how do you like me now this is still longer yet"
android:layout_margin="3dp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:singleLine="true"
android:gravity="center"
android:ellipsize="end"
android:inputType="text"
/>
<Button
android:text="Hello2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<Button
android:text="Hello3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
【问题讨论】:
标签: android alignment tableview