2016-11-28 20 views
0

私はAndroidを使い始めたばかりで、ログイン画面を含む最初のアプリを開発していました。ScrollView/LinearLayoutの下にViewを配置

最初は、RelativeLayoutAdViewを使用していました。または、他のビューは、android:layout_alignParentBottom="true"を使用して、親の一番下に正しく配置されていました。

次に、材料ガイドラインについては、LinearLayoutScrollViewとしたXMLを参照していました。 AdViewを一番下に置くことはできません。このXMLをAndroidスタジオにインポートしてみてください。ここで回答を検索すると、私はRelativeLayoutの中に入れて、android:layout_alignParentBottom="true"を再度使用しましたが成功しませんでした。私はAndroidのユーザーがこれでやったことを知っています。私は彼らが私を助けることを願っています。

だから、として私の基本的な質問を一覧:

  • あなたは私のOPがログイン画面の活動のためにScrollView使用している実際の使用を伝えることはできますか?アクティビティのUIを処理する方法がわかっている場合は、何を使用するべきかについて、2つ以上のヒントを投稿できますか?どんな先端も高く評価されるでしょう。
  • メイン質問 - AdViewをどのようにして底部に置きますか?説明をいただければ幸いです。

ありがとう。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:background="#FFB74D"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingTop="15dp" 
     android:paddingLeft="24dp" 
     android:paddingRight="24dp" 
     android:backgroundTintMode="src_atop"> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:gravity="center" 
       android:text="Gyaanify" 
       android:textSize="55sp" 
       android:textColor="#FF3D00" 
       android:textStyle="normal|bold" 
       android:textAllCaps="false" 
       android:textAlignment="center" 
       android:fontFamily="cursive" 
       android:layout_margin="10dp" /> 

     </RelativeLayout> 

     <!-- Email Label --> 
     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:layout_marginBottom="8dp"> 
      <EditText android:id="@+id/etUserName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textEmailAddress" 
       android:hint="Email" /> 
     </android.support.design.widget.TextInputLayout> 

     <!-- Password Label --> 
     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:layout_marginBottom="8dp"> 
      <EditText android:id="@+id/etPassword" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textPassword" 
       android:hint="Password"/> 
     </android.support.design.widget.TextInputLayout> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/btn_login" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      android:layout_marginBottom="24dp" 
      android:padding="20dp" 
      android:text="Login" 
      android:onClick="OnLogin" 
      android:background="#EF6C00" 
      android:textColor="@android:color/background_light" /> 

     <TextView android:id="@+id/link_signup" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="No account yet? Create one" 
      android:gravity="center" 
      android:textSize="16dip" 
      android:layout_marginTop="40dp" /> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/btn_register" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="24dp" 
      android:text="Register @ Gyaanify" 
      android:onClick="OnRegister" 
      android:padding="20dp" 
      android:layout_marginTop="10dp" 
      android:background="#EF6C00" 
      android:textColor="@android:color/background_light" /> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:orientation="vertical" 
      android:layout_alignParentBottom="true"> 

     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_alignParentBottom="true" 
      ads:adSize="BANNER" 
      ads:adUnitId="@string/banner_ad_unit_id"> 
     </com.google.android.gms.ads.AdView> 
     </RelativeLayout> 

    </LinearLayout> 
</ScrollView> 

答えて

1

あなたが画面全体を埋めなければならないScrollViewを使用するたびに:)、それはandroid:layout_width="match_parent" android:layout_height="match_parent"属性を持つ必要があります。これはあなたのコードでも当てはまります。しかし、内側のLinearLayoutにはandroid:layout_width="match_parent" android:layout_height="wrap_content"があるはずです。

さて、画面の下部にAdViewを配置し、その上のすべてのコンテンツのスクロールを持っている、あなたは以下のレイアウト構造を必要とする:1にScrollView重みを設定

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <!-- all your content here --> 

     </LinearLayout> 
    </ScrollView> 

    <com.google.android.gms.ads.AdView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

はあなたのことを確認しますAdViewは下部に固執しています。

関連する問題