Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于Android表单的布局_Java_Android_Eclipse_Layout_Ui Design - Fatal编程技术网

Java 基于Android表单的布局

Java 基于Android表单的布局,java,android,eclipse,layout,ui-design,Java,Android,Eclipse,Layout,Ui Design,我试图在Android上实现以下布局(目标API 18,最小API 8) 我对安卓系统还比较陌生,并提出了以下布局文件(activity\u main.xml)。我对Linear与Relative布局有所了解,如果有人能在这方面提供一些意见,我将不胜感激 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/too

我试图在Android上实现以下布局(目标API 18,最小API 8)

我对安卓系统还比较陌生,并提出了以下布局文件(
activity\u main.xml
)。我对
Linear
Relative
布局有所了解,如果有人能在这方面提供一些意见,我将不胜感激

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/task_name"
    android:textSize="14sp" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/textView1"
    android:ems="10"
    android:hint="@string/task_name_hint"
    android:inputType="text" />

<DatePicker
    android:id="@+id/dpResult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/textView1"
    android:layout_marginTop="8dp" />

<RadioGroup
    android:id="@+id/priority_radios"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/dpResult"
    android:inputType="text"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/first_radio" />

    <RadioButton
        android:id="@+id/second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/second_radio"/>


    <RadioButton
        android:id="@+id/third"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/third_radio" />

<RadioButton
    android:id="@+id/none"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/none_radio" 
    android:checked="true" />

</RadioGroup>


<RadioGroup
    android:id="@+id/category_radios"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/priority_radios"
    android:inputType="text"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/long_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/first_radio" />

    <RadioButton
        android:id="@+id/short_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/second_radio"/>


    <RadioButton
        android:id="@+id/new_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/third_radio" />


</RadioGroup>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/tag_name"
    android:textSize="14sp" />

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/tag_arrays"
    android:prompt="@string/tag_prompt" 
    android:layout_below="@id/category_radios" 
    android:layout_toRightOf="@id/textView2" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/spinner1"
    android:text="@string/create_task" />

</RelativeLayout>

这似乎是一个相当简单的布局。可以为每行使用垂直父线性布局,然后使用多个水平线性布局

<?xml version="1.0" encoding="utf-8"?>
<!-- PARENT LAYOUT -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/line1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Task name"/>

    <EditText android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter task name"/>
</LinearLayout>

<LinearLayout android:id="@+id/line2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <!-- SECOND LINE -->

</LinearLayout>

<LinearLayout android:id="@+id/line3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <!-- THIRD LINE -->
</LinearLayout>


我会像您一样使用RelativeLayout作为容器,然后使用一些LinearLayout和RadioGroup(从LinearLayout继承)

现在这是我得到的结果(注意,我将中间部分留空) -无论我使用的图片看起来像是textview的组合(这只是我手边的一个9补丁),但图片与你的不匹配

通过使用此布局

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ccc"
    android:orientation="vertical"
    >
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1.5"
        android:layout_margin="4dp"
        >
        <ImageButton
            android:id="@+id/imgBack"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher"
            android:layout_margin="4dp"
        />
        <ImageButton
            android:id="@+id/imgFore"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_toRightOf="@id/imgBack"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher"
            android:layout_margin="4dp"
        />
        <ImageButton
            android:id="@+id/imgExit"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_toRightOf="@id/imgFore"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher"
            android:layout_margin="4dp"
        />
        <ImageButton
            android:id="@+id/imgHome"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_toRightOf="@id/imgExit"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher"
            android:layout_margin="4dp"
        />
        <ImageButton
            android:id="@+id/imgFind"
            android:layout_width="32dp"
            android:layout_height="24dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher"
            android:layout_margin="4dp"
        />
        <TextView
            android:id="@+id/txtAddress"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/imgHome"
            android:layout_toLeftOf="@id/imgFind"
            android:layout_centerVertical="true"
            android:background="@drawable/combo_opt_m"
            android:layout_margin="4dp"
        />
    </RelativeLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="7.5"
        android:background="#fff"
        >

    </LinearLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        >
        <ImageButton
            android:id="@+id/imgFoot"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher"
            android:layout_margin="4dp"
        />
    </RelativeLayout>
</LinearLayout>

为了使应用程序全屏显示

感谢您的回复+1,请您发布一个示例来说明同样的问题。非常有效,谢谢!谢谢你的回复+1,你能不能发布一个例子来说明同样的问题。只需要一个基本的粗略布局就可以了,而不需要添加每个控件的属性。好的,让我看看我能做些什么谢谢你把这些放在一起,帮了大忙!!
@Override
protected void onCreate(
    final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // Make this activity, full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Hide the Title bar of this activity screen
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.form);
}