Reputation: 572
I have a tricky situation that I can't seem to wrap my head around. I've got an Android form. I have three elements, a label, a text field (read-only because it's set by a date picker) and a button. Here's what the code looks like:
<!-- container: each row in the form stacks vertically -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip"
android:orientation="vertical" >
<!-- Here's the date picker element I'm trying to figure out -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10.0dip" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="@string/set_date_label"
android:textColor="#ffffff"/>
<EditText
android:id="@+id/eventDate"
android:layout_width="0dp"
android:layout_weight="0.50"
android:layout_height="wrap_content"
android:inputType="date"
android:background="#ffffff"
android:focusable="false"
android:maxLines="1" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="@string/set_date_text"
/>
</LinearLayout>
</LinearLayout>
Now, my form looks mostly correct. But the problem is that the button is vertically taller than the text field, and so it pushes the rows in my form further apart than I'd like. (I can't post a screenshot, because I just joined and don't have enough reputation points. Huh.)
I've been Googling everywhere to try and find a solution, but I just can't seem to figure it out. It's got to be something simple, but I've been banging my head against the desk for a while now :)
Any suggestions? Thank you so much!
Upvotes: 2
Views: 1162
Reputation: 193
Without actually setting the same height for each element, I don't think they will turn out to have exactly the same height.
But one thing you could do is setting the minimum height of the button to zero, which will most likely fix your problem that the button is stretching the whole line.
Do so by using android:minHeight="0px"
inside the button.
Upvotes: 2
Reputation: 1362
Try setting your TextView
, EditText
and Button
's layout-height
to match_parent
.
Upvotes: 1