2016-09-07 17 views
0

アンドロイドのレイアウトに問題があります。 私はtextviewの相対レイアウトを持ち、画像が重なり合っていて、ビューの下部に2つのボタンを追加したいと思います。もう1つは近くにあり、ビューの幅いっぱいになります。ここでは、manifest.xmlRelativeLayoutの下部にある2つのボタン1つ近く - Android

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    android:orientation="vertical" 
    android:id="@+id/RecordAccelDataLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <ImageView 
     android:layout_gravity="center" 
     android:longClickable="false" 
     android:layout_width="283dp" 
     android:layout_height="418dp" 
     android:src="@mipmap/bg_thand" 
     android:adjustViewBounds="false" 
     android:alpha="0.1" /> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/rectangle"> 

     <TextView 
      android:textSize="20sp" 
      android:gravity="center_horizontal" 
      android:id="@+id/rec_progress_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="30dp" 
      android:text="@string/title_activity_record_accel_data" 
      /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <com.adrenergic.tremorsense.circleGraph 
       android:layout_gravity="center" 
       android:id="@+id/progressgraph" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true"/> 

      <TextView 
       android:textSize="20sp" 
       android:id="@+id/accelText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/recording" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:textIsSelectable="true" 
       /> 

      <Button 
       android:textColor="#ffffff" 
       android:layout_width="100dp" 
       android:id="@+id/back" 
       android:layout_height="50dp" 
       android:text="@string/back" 
       android:layout_gravity="center" 
       android:layout_marginBottom="3dip" 
       android:onClick="goBack" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" /> 

      <Button 
       android:textColor="#ffffff" 
       android:layout_width="100dp" 
       android:layout_height="50dp" 
       android:layout_gravity="center" 
       android:text="@string/stats" 
       android:onClick="goBack" 
       android:id="@+id/stats" 
       android:layout_marginBottom="3dip" 
       android:layout_centerHorizontal="true" 
       android:layout_alignParentBottom="true" 
       android:layout_toRightOf="@+id/back"/> 
     </RelativeLayout> 
    </LinearLayout> 
</FrameLayout> 

レイアウトがこのように表示されます。

enter image description here

私は2つのボタンは同じ位置に表示されますが、centeredと、彼らは均等幅でビューを埋めることをことをしたいと思います。

あなたが私を助けてくれることを願っています。

+0

なぜあなたは同じ 'weight'を持つ別のリニアレイアウトの下にボタンを試してみませんか?あなたはそれを試しましたか?それが助けてくれることを願って。 –

+0

はい私は試みましたが、線形レイアウトがビューの上部に表示されます –

+0

RaghavendraとRamesh Kumar、Sourav Kantaの回答は以下の通りです –

答えて

2

あなたのボタンレイアウトを変更することはできますか?以下のサンプルを試してみてください。

<LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:weightSum="1"> 
      <Button 
       android:textColor="#ffffff" 
       android:layout_width="0dp" 
       android:id="@+id/back" 
       android:layout_weight="0.5" 
       android:layout_height="50dp" 
       android:text="@string/back" 
       android:layout_gravity="center" 
       android:layout_marginBottom="3dip" 
       android:onClick="goBack"/> 

      <Button 
       android:textColor="#ffffff" 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:layout_weight="0.5" 
       android:layout_gravity="center" 
       android:text="@string/stats" 
       android:onClick="goBack" 
       android:id="@+id/stats" 
       android:layout_marginBottom="3dip"/> 
      </LinearLayout> 
+1

素晴らしい!ありがとうございました –

+0

@ParideLetizia Glad!それは助けました:) – Raghavendra

0

こんにちは、あなたは、リニアレイアウトにボタンを入れて、親の下揃えることができます。

<?xml version="1.0" encoding="utf-8"?> 

<ImageView 
    android:layout_width="283dp" 
    android:layout_height="418dp" 
    android:layout_gravity="center" 
    android:adjustViewBounds="false" 
    android:alpha="0.1" 
    android:longClickable="false" 
    android:src="@mipmap/bg_thand" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/rectangle" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/rec_progress_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="30dp" 
     android:gravity="center_horizontal" 
     android:text="@string/title_activity_record_accel_data" 
     android:textSize="20sp" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <com.adrenergic.tremorsense.circleGraph 
      android:id="@+id/progressgraph" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_gravity="center" /> 

     <TextView 
      android:id="@+id/accelText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="@string/recording" 
      android:textIsSelectable="true" 
      android:textSize="20sp" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:orientation="horizontal"> 

      <Button 
       android:id="@+id/back" 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_gravity="center" 
       android:layout_marginBottom="3dip" 
       android:layout_weight="1" 
       android:onClick="goBack" 
       android:text="@string/back" 
       android:textColor="#ffffff" /> 

      <Button 
       android:id="@+id/stats" 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_gravity="center" 
       android:layout_marginBottom="3dip" 
       android:layout_toRightOf="@+id/back" 
       android:layout_weight="1" 
       android:onClick="goBack" 
       android:text="@string/stats" 
       android:textColor="#ffffff" /> 
     </LinearLayout> 
    </RelativeLayout> 
</LinearLayout> 

をそれに役立つだろう、これを確認してください。

0

android:weightは、お探しのものです。 2つのボタンを直線レイアウトの中に囲み、両方にandroid:weight = 1を追加します。例は次のようになります。

あなたは中央下にある中 spacerを追加し、このようにその spacerへの2つのボタンを整列する必要がある
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
> 

    <Button android:id="@+id/button1" 
      ... 
      android:layout_weight="1"/> 

    <View 
      android:id="@+id/space" 
      ... 
      android:layout_weight=".1"/> 

    <Button android:id="@+id/button2" 
      ... 
      android:layout_weight="1"/> 

</LinearLayout> 
0

<RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <com.adrenergic.tremorsense.circleGraph 
       android:layout_gravity="center" 
       android:id="@+id/progressgraph" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true"/> 

      <TextView 
       android:textSize="20sp" 
       android:id="@+id/accelText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:textIsSelectable="true" 
       /> 
      //Aligh Space in center with align to bottom 
       and set relation of two button to this spacer 
      <Space 
       android:layout_width="1px" 
       android:layout_height="1px" 
       android:layout_above="@+id/back" 
       android:layout_centerHorizontal="true" 
       android:layout_alignParentBottom="true" 
       android:id="@+id/space"/> 

      <Button 
       android:textColor="#ffffff" 
       android:layout_width="100dp" 
       android:id="@+id/back" 
       android:layout_height="50dp" 
       android:text="Back" 
       android:layout_gravity="center" 
       android:onClick="goBack" 
       android:layout_alignParentBottom="true" 
       android:layout_alignStart="@+id/accelText"/> 

      <Button 
       android:textColor="#ffffff" 
       android:layout_width="100dp" 
       android:layout_height="50dp" 
       android:layout_gravity="center" 
       android:text="Status" 
       android:onClick="goBack" 
       android:id="@+id/stats" 
       android:layout_alignParentBottom="true" 
       android:layout_toStartOf="@+id/space"/> 


     </RelativeLayout> 
0

Linear Layoutの内側に追加Buttonで作られたこのlayout変更を使用しますweightandroid:gravity="bottom"android:orientation="horizontal"と入力してください。

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RecordAccelDataLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ImageView 
     android:layout_width="283dp" 
     android:layout_height="418dp" 
     android:layout_gravity="center" 
     android:adjustViewBounds="false" 
     android:alpha="0.1" 
     android:longClickable="false" 
     android:src="@drawable/common_ic_googleplayservices" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/common_ic_googleplayservices" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/rec_progress_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="30dp" 
      android:gravity="center_horizontal" 
      android:text="Progress" 
      android:textSize="20sp" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <com.adrenergic.tremorsense.circleGraph 
       android:id="@+id/progressgraph" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:layout_gravity="center" /> 

      <TextView 
       android:id="@+id/accelText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:text="REcording" 
       android:textIsSelectable="true" 
       android:textSize="20sp" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="bottom" 
       android:orientation="horizontal" 
       android:weightSum="1"> 

       <Button 
        android:id="@+id/back" 
        android:layout_width="100dp" 
        android:layout_height="50dp" 
        android:layout_weight="0.50" 
        android:onClick="goBack" 
        android:text="Back" 
        android:textColor="#ffffff" /> 

       <Button 
        android:id="@+id/stats" 
        android:layout_width="100dp" 
        android:layout_height="50dp" 
        android:layout_weight="0.50" 
        android:onClick="goBack" 
        android:text="Stats" 
        android:textColor="#ffffff" /> 

      </LinearLayout> 
     </RelativeLayout> 
    </LinearLayout> 
</FrameLayout> 

enter image description here

+0

OPに感覚的な答えがある場合は、アップヴォートでお答えします。 –

関連する問題