在布局底部滚动视图有两个按钮 [英] Scroll view with two buttons at the bottom of the layout
问题描述
我想在布局的顶部将有两个Textviews创建布局,这将有一个滚动视图,所述srollview内部。在该中心将有两个Edittexts并在布局的底部,将有两个按钮。 但是,一切都将是主要的滚动视图下。
I want to create a layout which will have a scrollview, inside the srollview at the top of the layout there will be two Textviews. In the center there will be two Edittexts and at the bottom of the layout, there will be two buttons. But everything will be under the main scrollview.
我的要求的可视描述
我已经做了一些编码它滚动顶尖的内容,但保留的按钮在底部哪个不是预期的功能的滚动型的。
I have done some coding which scrolls the top content but keeps the buttons at the bottom out of the scrollview which is not the expected functionality.
我的布局编码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<ScrollView
android:id="@+id/my_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/LinearLayout01"
android:scrollbars="horizontal" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/welcomeToStudy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Welcome to xxxxxxxxxxxxxxx!"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#54575A"
android:textSize="28sp" />
<TextView
android:id="@+id/pleaseEnter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/welcomeToStudy"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="Please enter your details xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx."
android:textSize="20sp" />
<EditText
android:id="@+id/emailSignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/pleaseEnter"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textSize="24sp" >
</EditText>
<EditText
android:id="@+id/passwordSignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/emailSignUp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true"
android:textSize="24sp" >
</EditText>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_marginTop="5dp">
<Button
android:id="@+id/signUpBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/next_button_selector"
android:text="Sign Up"
android:textColor="#FFFFFF"
android:textSize="20sp" >
</Button>
<Button
android:id="@+id/registerWithFb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/next_button_xhdpi_facebook"
android:text="Sign up with Facebook"
android:textColor="#FFFFFF"
android:textSize="20sp" >
</Button>
</LinearLayout>
</RelativeLayout>
我应该怎么做,以获得预期的输出?
推荐答案
在 peguerosdc的答案的基础上,我做了一些修改,得到了整个事情的工作。新的布局code:
On the basis of peguerosdc's answer, I made some modifications and got the whole thing to work. The new layout code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<ScrollView
android:id="@+id/my_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/main_relative_layout"
android:layout_width="match_parent"
android:layout_height="53dp" >
<TextView
android:id="@+id/welcomeToStudy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text="Welcome to xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#54575A"
android:textSize="28sp" />
<TextView
android:id="@+id/pleaseEnter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/welcomeToStudy"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Please enter your details xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx."
android:textSize="20sp" />
<EditText
android:id="@+id/emailSignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/pleaseEnter"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textSize="24sp" >
</EditText>
<EditText
android:id="@+id/passwordSignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/emailSignUp"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true"
android:textSize="24sp" >
</EditText>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/passwordSignUp"
android:layout_marginTop="35dp"
android:orientation="vertical" >
<Button
android:id="@+id/signUpBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/next_button_selector"
android:text="Sign Up"
android:textColor="#FFFFFF"
android:textSize="20sp" >
</Button>
<Button
android:id="@+id/registerWithFb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/next_button_xhdpi_facebook"
android:text="Sign up with Facebook"
android:textColor="#FFFFFF"
android:textSize="20sp" >
</Button>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
的方法是根据以适应屏幕的布局的设备屏幕大小编程以改变 main_relative_layout
值。我没有用一个空格,虽然,我对准 LinearLayout01
到 ParentBottom
。
The approach is to change the main_relative_layout
value programatically according to the device screen size in order to accommodate the layout in the screens. I did not use a whitespace though, I aligned the LinearLayout01
to ParentBottom
.
在code来获得设备的屏幕尺寸和改变 main_relative_layout
编程(在的onCreate
)
The code to get the screen size of the device and change main_relative_layout
programatically (inside onCreate
):
// for button placement purely design workout
DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
Log.e("Screen height:", "" + dpHeight);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.main_relative_layout);
rl.getLayoutParams().height = dpToPx((int) dpHeight - 70);
该方法 dpToPx
:
//method to convert from dp to px
public int dpToPx(int dp) {
DisplayMetrics displayMetrics = SignUp.this.getResources().getDisplayMetrics();
int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
return px;
}
这篇关于在布局底部滚动视图有两个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!