android - 在android中输入数据的自定义布局

标签 android xml

我正在努力实现如图所示的东西


rounded_edittext.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >

    <solid android:color="#FFFFFF" />

    <corners
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" />

</shape>

search_page.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#C0C0C0"
    android:orientation="vertical" >

    <TableRow
        android:id="@+id/row1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="City" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:padding="5dip" />
    </TableRow>

    <TableRow
        android:id="@+id/row1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:inputType="date"
            android:padding="5dip" >

            <requestFocus />
        </EditText>
    </TableRow>

    <TableRow
        android:id="@+id/row1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Type" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Breakfast" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lunch" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Dinner" />
    </TableRow>

    <TableRow
        android:id="@+id/row1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Search" />
    </TableRow>

</LinearLayout>

我有如下输出::

enter image description here


如何修改我的 xml 以便我可以实现如下所示::

enter image description here

我正在尝试获得与上面完全相同的布局

  • 我还尝试使用 edittext 作为日期,如 second 所示 pic wather than I have reached
  • 我还试图让方框行中的所有内容显示为 以上

有什么想法吗?

希望我说清楚了!

最佳答案

try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="1"
    >
    <TextView 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="City"
        android:layout_weight=".25"/>
    <EditText 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight=".75"/>
</LinearLayout>

<View 
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/black"/>

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="1"
    >
    <TextView 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="date"
        android:layout_weight=".25"/>
    <EditText 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight=".25"/>

    <EditText 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight=".25"/>

    <EditText 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight=".25"/>

    <EditText 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight=".25"/>
</LinearLayout>

<View 
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/black"/>

 <LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="1"
    >
    <TextView 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="type"
        android:layout_weight=".25"/>
    <Button 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="breakfast"
        android:textSize="10sp"
        android:layout_weight=".25"/>

    <Button 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="lunch"
         android:textSize="10sp"
        android:layout_weight=".25"/>

    <Button 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="dinner"
         android:textSize="10sp"
        android:layout_weight=".25"/>

</LinearLayout>

<View 
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/black"/>

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="Search"/>

关于android - 在android中输入数据的自定义布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19179141/

相关文章:

android - 如何在点击时为 ListView 项目设置背景并在其他点击时动态更改

android - GetCameraDisplayOrientation 始终返回 0

java - JAXB:在 map 上使用 @XmlIDREF

java - 我想自定义 android youtube 播放器 api 的布局

Java:JAXB:JAXBElement<Calendar> 到 xs:date 的编码不正确

java - Android 套接字连接错误 IP 导致卡住

android - 如何在android中的退格键上删除哪个字符

android - 用于 ListView 宽度的 wrap_content

sql - SQL Server XML 数据类型中的 LIKE 比较

xml - 使用 Perl 获取 XML 文档中标记的行号?