2015-07-20 3 views
-1

Я пытаюсь сделать нижнюю панель с помощью панели инструментов и выровнять ее до нижней части родителя. Вот как это выглядит:Android toolbar Проблема с макетами

Bottom Toolbar

Но каким-то образом, как указано в изображении, их много пустого пространства, благодаря которой макет не точно по центру. Почему это происходит?

bottom_tool_bar.xml

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/ColorPrimaryLight" 
android:elevation="4dp" 
android:layout_alignParentBottom="true" 
> 

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

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/origin_select" 
     android:src="@mipmap/ic_action_play" 
     android:background="@drawable/feedback_background" 
     android:onClick="choose_origin_button" 
     /> 


    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/destination_select_select" 
     android:src="@mipmap/ic_action_stop" 
     android:background="@drawable/feedback_background" 
     android:onClick="choose_destination_button"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/poi_select" 
     android:src="@mipmap/ic_action_pause" 
     android:background="@drawable/feedback_background" 
     android:onClick="choose_interest_button"/> 


</LinearLayout> 
</android.support.v7.widget.Toolbar> 

Файл макета для соответствующей деятельности:

<include 
    android:id="@+id/tool_bar" 
    layout="@layout/tool_bar" 
    > 
</include> 

<include 
    android:id="@+id/bottom_tool_bar" 
    layout="@layout/bottom_tool_bar"> 
</include> 

<fragment 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/plot_path_map" 
    android:layout_below="@+id/tool_bar" 
    android:layout_above="@+id/bottom_tool_bar" 
    android:name="com.google.android.gms.maps.MapFragment" 
    /> 
<Button 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:id="@+id/submit_button" 
    android:text="Submit" 
    android:textColor="#FFFFFF" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/feedback_background" 
    android:layout_centerVertical="true" 
    android:textSize="20sp" 
    android:layout_alignParentBottom="true" 
    android:visibility="invisible" 
    android:onClick="submit_button_click" 
    /> 
</RelativeLayout> 
+0

http://stackoverflow.com/questions/26455027/android-api-21-toolbar-padding –

+0

Значит, любой из ответов работал на вас? – commonSenseCode

ответ

1

Если вы хотите разместить на панели инструментов в нижней части, это то, что вы должны делать.

Используйте LinearLayout с alignParentBottom = «истинный»

<RelativeLayout 
android:id="@+id/mainLyt" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<!-- Some layout things --> 

<ScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_above="@+id/bottomBar"> 

<!-- some scrolling content --> 
</ScrollView> 

<LinearLayout 
android:id="@+id/bottomBar" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:orientation="horizontal" 
android:layout_alignParentBottom="true"> 

<!-- Some Buttons --> 
</LinearLayout> 

</RelativeLayout> 

Как вы упомянули о интервал, который я считаю, другой вопрос, вы можете изменить его, используя следующие атрибуты внутри ToolBar.

app:contentInsetLeft="0dp" 
app:contentInsetStart="0dp" 
+0

Это вроде как сработало. Пространство слева теперь исчезло, а макет по центру. Однако пространство сверху и снизу все еще существует. Любое решение для этого? – Bluesir9

0

сделать отдельный файл макета и назовите его tool_bar.xml и убедитесь, что LinearLayout это ваше корневой макет.

Затем в типе деятельности это:

<include 
    android:id="@+id/tool_bar" 
    layout="@layout/tool_bar" 
    ></include> 

Затем дает weight из 0,3 всех ваших ImageViews и layout:width и layout:height в wrap_content

+0

Это уже отдельный файл макета, который я включаю в файл макета активности. Ваши изменения не улучшились. – Bluesir9

+0

В вашем размещенном xml вы не включили файлы макета. если вы обновили xml, отредактируйте OP. –

0

Для центрирования просмотров у вас есть много вариантов два (я считаю, что второй лучше):

F Первая включает weigthsum в ваш linearlayout, мне нравится использовать 100, так как это помогает мне думать в процентах, а затем включать 2 stump framelayout, чтобы подтолкнуть ваши изображения к горизонтальному центру и позволить им сохранять отзывчивые свойства, используя такой вес:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="100" 
     android:orientation="horizontal" 
     > 
     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="30"/> 
     <ImageView 
      android:id="@+id/origin_select" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="13" 
      android:background="@drawable/feedback_background" 
      android:onClick="choose_origin_button" 
      android:src="@mipmap/ic_action_play" 
      /> 


     <ImageView 
      android:id="@+id/destination_select_select" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="13" 
      android:background="@drawable/feedback_background" 
      android:onClick="choose_destination_button" 
      android:src="@mipmap/ic_action_stop"/> 

     <ImageView 
      android:id="@+id/poi_select" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="13" 
      android:background="@drawable/feedback_background" 
      android:onClick="choose_interest_button" 
      android:src="@mipmap/ic_action_pause"/> 
     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="30"/> 

    </LinearLayout> 

Как вы можете видеть, как framelayout не имеет ничего внутри, но они помогают вам подтолкнуть ваши другие ImageViews к центру, они оба дают вам 60% пространства и оставляют вам только 40% для вашего ImageViews, таким образом, у каждого из них 13% ,

С другой стороны, вы можете использовать RelativeLayout в качестве родительского элемента вместо LinearLayout и позиционировать Imageview с id: destination_select_select выравнивать центр до родителя как по горизонтали, так и по вертикали, а затем позиционировать два других изображения в стороне от центра, середина. Эта опция может быть лучшим:

Как это:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 
     <ImageView 
      android:id="@+id/origin_select" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="@drawable/feedback_background" 
      android:onClick="choose_origin_button" 
      android:src="@mipmap/ic_action_play" 
      android:layout_alignLeft="@+id/destination_select_select" 
      /> 


     <ImageView 
      android:id="@+id/destination_select_select" 
      android:layout_width="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_height="match_parent" 
      android:background="@drawable/feedback_background" 
      android:onClick="choose_destination_button" 
      android:src="@mipmap/ic_action_stop"/> 

     <ImageView 
      android:id="@+id/poi_select" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignRight="@+id/destination_select_select" 
      android:background="@drawable/feedback_background" 
      android:onClick="choose_interest_button" 
      android:src="@mipmap/ic_action_pause"/> 

    </RelativeLayout> 
0

Используйте ниже линии, чтобы избежать левой боковой зазор в классе активности.

mToolbar.setContentInsetsAbsolute(0, 0); 

Посмотрите код ниже, чтобы избежать положения сверху и снизу.

<ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:id="@+id/origin_select" 
      android:src="@mipmap/ic_action_play" 
      android:background="@drawable/feedback_background" 
      android:onClick="choose_origin_button" 
      /> 

На ваш взгляд изображения width должен быть wrap_content и height должны быть 0dp

0

Чтобы избежать верхнего и нижнего пространства,

Добавить эту линию

android:minHeight="0dp"

к <android.support.v7.widget.Toolbar> свойств.

Смежные вопросы