1

ここではAndroidアプリのUIを作成しようとしています。私は上部にいくつかのボタンとロゴを持っています。アプリをデザインしているうちにボタンの下部に空白があることがわかりました。私はそのスペースを使用して、すべてのボタンが空白部分の内側に正しく配置されるようにしたいと思います。ボタンは、ロゴからデバイス画面のボタンまでの下からのデザインです。ボタンコントロールを画面の解像度に関係なく画面に収まるように設定します

enter image description here 私はこのコードを実行した

Main.axml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#0B95BA" 
    android:id="@+id/relativeLayout_container"> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="87.5dp" 
     android:layout_alignParentTop="true" 
     android:scaleType="fitXY" 
     android:gravity="center" 
     android:paddingLeft="10dp" 
     android:src="@drawable/LogoHere" 
     android:id="@+id/imgLogoHere" 
     android:layout_marginBottom="0.0dp" 
     android:layout_marginLeft="0.0dp" /> 
    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/bottom_container" 
     android:layout_below="@id/imgLogoHere" 
     android:fillViewport="false" 
     android:orientation="vertical" 
     android:padding="10dp"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_below="@id/scrollView"> 
      <Button 
       android:id="@+id/btnVisit" 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:text="Visit" 
       android:layout_marginTop="5dp" /> 
      <Button 
       android:text="Our" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:id="@+id/btnOur" 
       android:layout_marginTop="5dp" /> 
      <Button 
       android:text="Ours" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:id="@+id/btnOurs" 
       android:layout_marginTop="5dp" /> 
      <Button 
       android:text=" Contact Us" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:id="@+id/btnContactUs" 
       android:layout_marginTop="5dp" /> 
      <Button 
       android:text="Test" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:id="@+id/btnTest" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:layout_marginTop="5dp" /> 
      <Button 
       android:id="@+id/btnView" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:text="View" 
       android:layout_marginTop="5dp" /> 
      <Button 
       android:id="@+id/btnOrderEntry" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:text="Order Entry" 
       android:layout_marginTop="5dp" /> 
      <Button 
       android:id="@+id/btnIntranet" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:textSize="15sp" 
       android:textColor="#FFFFFF" 
       android:background="@drawable/ButtonStyle" 
       android:text="Intranet" 
       android:layout_marginTop="5dp" /> 
     </LinearLayout> 
    </ScrollView> 
    <LinearLayout 
     android:id="@+id/bottom_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" /> 
</RelativeLayout> 

ユーザーが感じることができないように、それがより明確に私はボタンになりたい帳票画像は、任意のデバイス上の空白の領域に表示されます不快。アプリを使用している間。

また、画面にUIを読み込み、デバイスの解像度を動的に表示できるようにすることをお勧めします。 advanace

+1

各ボタンに余裕を持たせて、再生時には下のスペースをカバーします –

答えて

1

変更

android:fillViewport="false" 

scrollViewにデバイスの画面が表示されないため、空白が表示されます。

scrollview

+0

返信いただきありがとうございます.... – Pritish

2

おかげで、各Buttonについてandroid:layout_margin="10dp"またはandroid:layout_margin="12dp"

を追加します。

これを参照してください。

<Button 
     android:id="@+id/btnIntranet" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="5dp" 
     android:layout_weight="1" 
     android:layout_margin="10dp" 
     android:background="@mipmap/ic_launcher" 
     android:text="Intranet" 
     android:textColor="#FFFFFF" 
     android:textSize="15sp" /> 

すべてButtonsために同じ操作を行います。

あなた scrollView
android:fillViewport="true" 

+0

あなたはどんなデバイスでも動的にそれを作ることができるように考えていますか? – Pritish

+1

@MartinPあなたの 'Layout'で' Scroll View'を使用していますので、解像度のユーザがスクロールして簡単に見ることができる問題はありません。 –

+0

私は尋ねることが好きなことボタンのサイズを大きくすることができる方法は、ボタンの高さが非常に小さいので画像を見ることができることを意味します。テキストを読むのは難しいですか。 – Pritish

1

あなたのレイアウトは非常に直線的であるので、それがルートタグとしてLinearLayoutを使用することをお勧めします。

<LinearLayout 
    android:orientation="vertical" 
    other attributes here...> 

</LinearLayout> 

これは、このようなlayout_belowとして、その子のすべての相対的なレイアウト関連のものを削除できることを意味します。

画像ビューにweightを追加し、2またはその他の適切な数に設定します。もちろん、高さを0dpに設定します。

スクロールビューにウェイトを追加します。私は8がうまくいくと思います。また、高さを0dpに設定してください

直線レイアウトの高さを変更してください(スクロールビューの高さをmatch_parentに変更してください)。

私はそれをするべきだと思います。

1

Javaコードからウィジェットのレイアウトプロパティを制御して、異なる画面解像度にすることができます。

DisplayMetrics displayMetrics = getActivity().getApplicationContext().getResources().getDisplayMetrics(); 

float screenHeight = displayMetrics.heightPixels/displayMetrics.density; 
float requiredHeight = (screenHeight * 1)/8; 
final float scale = context.getResources().getDisplayMetrics().density; 
int buttonHeight = (int) ((int) requiredHeight * scale + 0.5f); 
buttonName.setHeight(buttonHeight); 

すべてのボタンの高さプロパティを設定します。

関連する問題