1

Я использую FloatingActionButton на странице с листингом моего приложения, я также хочу добавить searchBar. Но я не мог показать им эту страницу. Мои коды и скриншот отсутствуют. Как я могу показать searchBar?Xamarin Forms RelativeLayout Использование

FAB Github

Мои коды:

<ContentPage.Content> 
     <RelativeLayout> 
     <SearchBar 
      x:Name="searchBar" 
      Placeholder="Ara" 
      /> 
      <ContentView 
       RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
       RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"> 
       <ListView 
        x:Name="list" 
        BackgroundColor="White"> 
        <ListView.ItemTemplate> 
         <DataTemplate> 
          <TextCell 
           Text="{Binding .}" /> 
         </DataTemplate> 
        </ListView.ItemTemplate> 
       </ListView> 
      </ContentView> 
      <fab:FloatingActionButton 
       x:Name="fabBtn" 
       Source="plus.png" 
       Size="Normal" 
       Clicked="Handle_FabClicked" 
       NormalColor="Green" 
       RippleColor="Red" 
       RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=-75}" 
       RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=-75}" /> 
     </RelativeLayout> 
    </ContentPage.Content> 
</ContentPage> 

enter image description here

+0

плавающая кнопка действия на iOS? Вы уверены, что дизайн хорошо подходит для iOS? – Cheesebaron

+0

Да, он отлично работает. – ozmert75

+0

В любом случае, глядя на ваш код, ContentView перекрывает ваш SearchBar, поэтому вы его не видите. – Cheesebaron

ответ

1

@Cheesebaron правильно. Проблема в том, что взгляды друг на друга. Вместо этого вам нужно добавить ограничение на ContentView, чтобы оно было Y ниже searchBar. Рассмотрим что-то вроде этого:

<ContentView 
      RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
      RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}" 
      RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, Property=Height, ElementName=searchBar}" /> 

Примечание добавление RelativeLayout.YConstraint быть на основе Height в searchBar.