[英]How to achieve this layout in Android using Android Studio
I am trying to achieve the below layout in Android studio but I can't seem to get it working. 我正在尝试在Android Studio中实现以下布局,但似乎无法正常工作。
I have so far: 我到目前为止:
<FrameLayout 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"
tools:context="net.firstapp.myapplication.Main">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" // I want this to be a dropdown with options male and female
android:text="Name"
android:ems="10"
android:id="@+id/editText" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/editText2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="@+id/editText3" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editText4" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="@+id/editText5" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText6" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/editText7" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button4" />
</FrameLayout>
I am new to Android and I am not sure what I should do - I am struggling to make the above layout. 我是Android的新手,我不确定应该怎么做-我正在努力进行上述布局。
For dropdown you can user Spinner
: 对于下拉列表,您可以使用
Spinner
:
https://www.tutorialspoint.com/android/android_spinner_control.htm https://www.tutorialspoint.com/android/android_spinner_control.htm
To Manage layout you should use RelativeLayout
.. So you can get your view by managing them with properties of RelativeLayout
like LEFT_OF
, RIGHT_OF
etc : 管理布局你应该使用
RelativeLayout
。所以你可以将它们与性能管理让您的视图RelativeLayout
像LEFT_OF
, RIGHT_OF
等:
https://developer.android.com/reference/android/widget/RelativeLayout.html https://developer.android.com/reference/android/widget/RelativeLayout.html
https://www.mkyong.com/android/android-relativelayout-example/ https://www.mkyong.com/android/android-relativelayout-example/
http://androidexample.com/Relative_Layout_Basics_-_Android_Example/index.php?view=article_discription&aid=73 http://androidexample.com/Relative_Layout_Basics_-_Android_Example/index.php?view=article_discription&aid=73
You are using a framelayout as the parent view in your hierarchy. 您正在使用框架布局作为层次结构中的父视图。 Framelayouts are supposed to contain just one child view usually.
通常,框架布局仅包含一个子视图。 It will not let you achieve this list-like view.
它不会让您实现这种类似于列表的视图。 See more over here: FrameLayouts
在此处查看更多信息: FrameLayouts
The best option for you here would be to use a vertical LinearLayout as the parent. 在这里,您最好的选择是使用垂直LinearLayout作为父级。 Some LinearLayouts will have to be made childs of the parent LinearLayout too(for the views that are positioned side by side) See more here: LinearLayouts
有些LinearLayouts也必须成为父级LinearLayout的子级(对于并排放置的视图),请参见此处: LinearLayouts
RelativeLayouts seem to be a good option too RelativeLayouts似乎也是一个不错的选择
This shall get you going. 这会带你去。
<ScrollView>
<RelativeLayout>
<Spinner>
<EditText> //add minLines property
<RelativeLayout>
<EditText paddingRight="width of image view">
<ImageView alignParentRight=true>
</RelativeLayout>
<RelativeLayout>
<EditText>
<EditText> //use rightOf property
</RelativeLayout>
<TextView marginTop="20dp">
<EditText>
<EditText>
<RelativeLayout>
<TextView width="match_parent" leftOf="view">
<View width="1dp" centerHorizontal="true">
<TextView with ="match_parent" rightOf="view">
</RelativeLayout>
<TextView>
</RelativeLayout>
</ScrollView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.