Java Android-防止在HorizontalScrollView中剪切按钮文本?

Java Android-防止在HorizontalScrollView中剪切按钮文本?,java,c#,android,xamarin,Java,C#,Android,Xamarin,我在应用程序的底部有一个水平滚动视图,我希望里面的每个按钮宽度相等,但不是剪辑按钮文本。我尝试过使用线性布局、水平滚动视图和按钮的“布局宽度”,以及更改按钮权重 我的结果是:4个按钮正好填满屏幕宽度(这不是我想要的,因为用户需要意识到还有其他按钮可用),或者下面的屏幕截图(按钮文本剪辑) 我怎么能有相等的按钮宽度,没有文本剪辑和一个按钮部分显示,以表明滚动是可能的 我的活动。axml: <?xml version="1.0" encoding="utf-8"?> <Relat

我在应用程序的底部有一个水平滚动视图,我希望里面的每个按钮宽度相等,但不是剪辑按钮文本。我尝试过使用线性布局、水平滚动视图和按钮的“布局宽度”,以及更改按钮权重

我的结果是:4个按钮正好填满屏幕宽度(这不是我想要的,因为用户需要意识到还有其他按钮可用),或者下面的屏幕截图(按钮文本剪辑)

我怎么能有相等的按钮宽度,没有文本剪辑和一个按钮部分显示,以表明滚动是可能的

我的活动。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:id="@+id/my_layout"
    android:background="#FFFFFFFF">
    <HorizontalScrollView
        android:id="@+id/toolbar_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:fillViewport="true"
        android:scrollbars="none">
      <LinearLayout
    android:id="@+id/toolbar_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
        <LinearLayout
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="6"
            android:orientation="horizontal">
          <Button
              android:id="@+id/my_style_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_color"
              android:drawableLeft="@drawable/ic_color"
              style="@style/Toolbar_Button"
              android:singleLine="true"
              android:drawablePadding="10dp"
              android:layout_weight="1" />
          <Button
              android:id="@+id/my_behavior_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_behavior"
              android:drawableLeft="@drawable/ic_behavior"
              style="@style/Toolbar_Button"
              android:singleLine="true"
              android:drawablePadding="10dp"
              android:layout_weight="1" />
          <Button
              android:id="@+id/sound_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/sound"
              android:drawableLeft="@drawable/ic_sound"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/my_background_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_background"
              android:drawableLeft="@drawable/ic_background"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/share_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/social_share"
              android:drawableLeft="@drawable/ic_social_share"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/about_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/about"
              android:drawableLeft="@drawable/ic_about"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
        </LinearLayout>
      </LinearLayout>
    </HorizontalScrollView>
...
</RelativeLayout>
<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:listViewStyle">@style/ListViewStyle</item>
    <item name="android:textColor">#000000</item>
  </style>
  <style name="ListViewStyle" parent="@android:style/Widget.ListView">
    <item name="android:textColor">#000000</item>
    <item name="android:typeface">sans</item>
  </style>
  <style name="TextAppearance_Toolbar">
    <item name="android:textColor">#000000</item>
    <item name="android:typeface">sans</item>
  </style>
  <style name="Toolbar_Button" parent="android:Widget">
      <item name="android:layout_margin">5dp</item>
      <item name="android:background">@drawable/toolbar_button</item>   
  </style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
  <corners
  android:radius="10dp"
/>
  <solid
  android:color="#FFFFFF"
/>
  <padding
  android:left="10dp"
  android:top="10dp"
  android:right="10dp"
  android:bottom="10dp"
/>

  <stroke
  android:width="3dp"
  android:color="#878787"
/>
</shape>

...
styles.xml:

<?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:id="@+id/my_layout"
    android:background="#FFFFFFFF">
    <HorizontalScrollView
        android:id="@+id/toolbar_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:fillViewport="true"
        android:scrollbars="none">
      <LinearLayout
    android:id="@+id/toolbar_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
        <LinearLayout
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="6"
            android:orientation="horizontal">
          <Button
              android:id="@+id/my_style_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_color"
              android:drawableLeft="@drawable/ic_color"
              style="@style/Toolbar_Button"
              android:singleLine="true"
              android:drawablePadding="10dp"
              android:layout_weight="1" />
          <Button
              android:id="@+id/my_behavior_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_behavior"
              android:drawableLeft="@drawable/ic_behavior"
              style="@style/Toolbar_Button"
              android:singleLine="true"
              android:drawablePadding="10dp"
              android:layout_weight="1" />
          <Button
              android:id="@+id/sound_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/sound"
              android:drawableLeft="@drawable/ic_sound"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/my_background_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_background"
              android:drawableLeft="@drawable/ic_background"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/share_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/social_share"
              android:drawableLeft="@drawable/ic_social_share"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/about_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/about"
              android:drawableLeft="@drawable/ic_about"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
        </LinearLayout>
      </LinearLayout>
    </HorizontalScrollView>
...
</RelativeLayout>
<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:listViewStyle">@style/ListViewStyle</item>
    <item name="android:textColor">#000000</item>
  </style>
  <style name="ListViewStyle" parent="@android:style/Widget.ListView">
    <item name="android:textColor">#000000</item>
    <item name="android:typeface">sans</item>
  </style>
  <style name="TextAppearance_Toolbar">
    <item name="android:textColor">#000000</item>
    <item name="android:typeface">sans</item>
  </style>
  <style name="Toolbar_Button" parent="android:Widget">
      <item name="android:layout_margin">5dp</item>
      <item name="android:background">@drawable/toolbar_button</item>   
  </style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
  <corners
  android:radius="10dp"
/>
  <solid
  android:color="#FFFFFF"
/>
  <padding
  android:left="10dp"
  android:top="10dp"
  android:right="10dp"
  android:bottom="10dp"
/>

  <stroke
  android:width="3dp"
  android:color="#878787"
/>
</shape>

@样式/列表视图样式
#000000
#000000
桑
#000000
桑
5dp
@可绘图/工具栏按钮
工具栏按钮.xml:

<?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:id="@+id/my_layout"
    android:background="#FFFFFFFF">
    <HorizontalScrollView
        android:id="@+id/toolbar_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:fillViewport="true"
        android:scrollbars="none">
      <LinearLayout
    android:id="@+id/toolbar_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
        <LinearLayout
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="6"
            android:orientation="horizontal">
          <Button
              android:id="@+id/my_style_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_color"
              android:drawableLeft="@drawable/ic_color"
              style="@style/Toolbar_Button"
              android:singleLine="true"
              android:drawablePadding="10dp"
              android:layout_weight="1" />
          <Button
              android:id="@+id/my_behavior_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_behavior"
              android:drawableLeft="@drawable/ic_behavior"
              style="@style/Toolbar_Button"
              android:singleLine="true"
              android:drawablePadding="10dp"
              android:layout_weight="1" />
          <Button
              android:id="@+id/sound_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/sound"
              android:drawableLeft="@drawable/ic_sound"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/my_background_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/my_background"
              android:drawableLeft="@drawable/ic_background"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/share_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/social_share"
              android:drawableLeft="@drawable/ic_social_share"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
          <Button
              android:id="@+id/about_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/about"
              android:drawableLeft="@drawable/ic_about"
              style="@style/Toolbar_Button"
              android:drawablePadding="10dp"
              android:singleLine="true"
              android:layout_weight="1" />
        </LinearLayout>
      </LinearLayout>
    </HorizontalScrollView>
...
</RelativeLayout>
<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:listViewStyle">@style/ListViewStyle</item>
    <item name="android:textColor">#000000</item>
  </style>
  <style name="ListViewStyle" parent="@android:style/Widget.ListView">
    <item name="android:textColor">#000000</item>
    <item name="android:typeface">sans</item>
  </style>
  <style name="TextAppearance_Toolbar">
    <item name="android:textColor">#000000</item>
    <item name="android:typeface">sans</item>
  </style>
  <style name="Toolbar_Button" parent="android:Widget">
      <item name="android:layout_margin">5dp</item>
      <item name="android:background">@drawable/toolbar_button</item>   
  </style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
  <corners
  android:radius="10dp"
/>
  <solid
  android:color="#FFFFFF"
/>
  <padding
  android:left="10dp"
  android:top="10dp"
  android:right="10dp"
  android:bottom="10dp"
/>

  <stroke
  android:width="3dp"
  android:color="#878787"
/>
</shape>


@user3678528 Where?尝试android:layout\u width=“0dp”而不是android:layout\u width=“match\u parent”所有按钮。@user3678528我尝试了你的建议,但结果是一样的(每个按钮上都有文本剪辑)。@user3678528 Where?尝试android:layout\u width=“0dp”而不是android:layout\u width=“match\u parent”对于所有按钮。@user3678528我尝试了你的建议,但结果是一样的(每个按钮上都有文本剪辑)。