2016-10-03 14 views
1

ロゴ2のテキストとログインボタンを使用してログインページのUIを作成しようとしましたが、電話ポートレートモードでは非常に便利でしたが、そしてタブレットは問題を開始しました。相対レイアウトとリニアレイアウトでポートレートからランドスケープに切り替えるときに問題が発生する

私は、これはポートレートモードで完璧に動作しますが、我々は、風景の中に回転させるように画像サイズを小さく2つのソリューション

1.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativelayoutparent" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#fed2db" 
    android:orientation="vertical" 
    > 
     <RelativeLayout 
      android:id="@+id/linearlayout_parents" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <RelativeLayout 
       android:id="@+id/relativelayoutbasic" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="@dimen/margin20" 
       android:layout_marginRight="@dimen/margin20" 
       android:layout_centerInParent="true" 
       > 
       <EditText 
        android:id="@+id/userName" 
        android:inputType="text" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="[email protected]" 
        android:hint="UserName" 
        android:drawableStart="@mipmap/ic_launcher" 
        android:drawablePadding="10dp" 
        android:background="@null" 
        android:layout_marginTop="10dp" /> 
       <View 
        android:id="@+id/view" 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:background="#f7f7f7" 
        android:layout_below="@id/userName" 
        android:layout_marginTop="10dp" /> 
       <EditText 
        android:id="@+id/password" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/view" 
        android:inputType="textPassword" 
        android:hint="Password" 
        android:text="[email protected]" 
        android:drawablePadding="10dp" 
        android:background="@null" 
        android:drawableStart="@mipmap/ic_launcher" 
        android:layout_marginTop="10dp" /> 
       <Button 
        android:id="@+id/buttonLogin" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/password" 
        android:background="#f7f7f7" 
        android:text="Login" 
        android:textColor="@android:color/black" 
        android:textAllCaps="false" 
        android:textStyle="bold" 
        android:textSize="17sp" 
        android:layout_marginTop="10dp" /> 
       <Button 
        android:id="@+id/buttonForgotPassword" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/buttonLogin" 
        android:layout_marginTop="10dp" 
        android:text="Forgot Password ?" 
        android:textColor="@android:color/white" 
        android:textAllCaps="false" 
        android:background="@null" /> 
      </RelativeLayout> 

      <ImageView 
       android:id="@+id/imageview" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@mipmap/ic_launcher" 
       android:layout_marginTop="@dimen/margin20" 
       android:layout_above="@id/relativelayoutbasic" 
       android:layout_centerHorizontal="true"/> 
     </RelativeLayout> 
</RelativeLayout> 

を得ました。

は、肖像画で enter image description here

以下の例では、私は、次のソリューション

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativelayoutparent" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#3996db" 
    android:orientation="vertical" 
    > 

    <ScrollView 
     android:id="@+id/linearlayout_parentscroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:id="@+id/linearlayout_parents" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <ImageView 
       android:id="@+id/imageview" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@mipmap/ic_launcher" 
       android:layout_marginTop="@dimen/margin20" 
       android:layout_gravity="center_horizontal"/> 

      <RelativeLayout 
       android:id="@+id/relativelayoutbasic" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="@dimen/margin20" 
       android:layout_marginRight="@dimen/margin20" 

       > 
       <EditText 
        android:id="@+id/userName" 
        android:inputType="text" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="[email protected]" 
        android:hint="UserName" 
        android:drawableStart="@mipmap/ic_launcher" 
        android:drawablePadding="10dp" 
        android:background="@null" 
        android:layout_marginTop="10dp" /> 
       <View 
        android:id="@+id/view" 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:background="#f7f7f7" 
        android:layout_below="@id/userName" 
        android:layout_marginTop="10dp" /> 
       <EditText 
        android:id="@+id/password" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/view" 
        android:inputType="textPassword" 
        android:hint="Password" 
        android:text="[email protected]" 
        android:drawablePadding="10dp" 
        android:background="@null" 
        android:drawableStart="@mipmap/ic_launcher" 
        android:layout_marginTop="10dp" /> 
       <Button 
        android:id="@+id/buttonLogin" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/password" 
        android:background="#f7f7f7" 
        android:text="Login" 
        android:textColor="@android:color/black" 
        android:textAllCaps="false" 
        android:textStyle="bold" 
        android:textSize="17sp" 
        android:layout_marginTop="10dp" /> 
       <Button 
        android:id="@+id/buttonForgotPassword" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/buttonLogin" 
        android:layout_marginTop="10dp" 
        android:text="Forgot Password ?" 
        android:textColor="@android:color/white" 
        android:textAllCaps="false" 
        android:background="@null" /> 
      </RelativeLayout> 
     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

Aを試みた風景enter image description here

下記の例を示して示し。このソリューションでは、アンドロイド:layout_centerInParent = "true"というプロパティを使用することはできません 相対レイアウトのため、ソリューション1のようにログインテキストフィールドを中心にすることはできません。スクロールもしていますが、大きな画面では機能しません。中央には表示されないためです。

B.他の多くの問題を引き起こすため、スクロールビュー内で相対レイアウトを使用することはできません。

私は非常に多くの時間を費やしており、非常に多くのスタックオーバーフロー参照やその他も使用していますが、何も問題はありません。

どうか作業を進めてください。 ありがとうございます...

+0

あなたの問題は何ですか? – LightYearsBehind

答えて

1

ここでの問題は、幅/高さが"wrap_content"@mipmap/ic_launcher画像を使用していることです。
のでImageViewサイズはic_launcher画像サイズ
を上の基礎になるとic_launcher画像サイズが風景の中に
=>あなたのImageViewは肖像ため

、あなたのImageViewのための簡単なセット幅よりも小さくなっている肖像画よりもlandspaceが小さいです、その後、あなたの画像サイズは縦向きと横向きの両方で同じように見えます

<ImageView 
    android:id="@+id/imageview" 
    android:layout_width="100dp" // or whatever you want 
    android:layout_height="100dp" 
    android:src="@mipmap/ic_launcher" 
    android:layout_marginTop="@dimen/margin20" 
    android:layout_gravity="center_horizontal"/> 
+0

私は幅を追加し、次に異なるデバイスのためにそれは同じままであり、すべてのデバイスでよく見えません。景色のためにもっと大きなサイズの画像を入れようとしましたが、うまくいきませんでした。 –

+0

@RohitChaturvediあなたはdimen rightの使い方を知っていますか?あなたはイメージの幅に異なるdimenを作成してみてください。さらに、特定のスクリーンサイズのレイアウトファイルをさらに作成することもできます。 –

+0

はい、それは素晴らしい提案です。私は完全にdimenの使用を忘れました。私はそれが間違いなく機能すると確信しています。私はそれが問題を解決しない場合はさらに投稿します。ありがとうPhan Van Linh –

0

あなたは、指定リットルayoutを作成することができます -またはlayout-sw600dp-land(錠剤用)。

+0

はい、私は働くことができますが、私は1つのレイアウトだけで作業したいです。 - –

1

アプリを横向きモードで開いているときに、Androidは最初にランドスケープに固有のレイアウトがあるかどうかをチェックし、そうであればレイアウトフォルダに指定されたレイアウトではなく読み込みます。そのためには、のres /レイアウト、土地新しいフォルダを作成し、このフォルダにレイアウトフォルダからレイアウトをコピーし、それを編集し、美しい景観のレイアウトを作成する必要があります。

+0

私はあなたの意見に完全に同意し、その方法でも動作しますが、私は1つのレイアウトでしか動作しません。 –

関連する問題