标签: android-xml

Android TableLayout 行权重

我正在尝试创建一个表并向表中的列添加相同的空间。我的代码如下,但我的第二列没有与第一列相同的空间。就像您在我下面发布的图像中看到的那样,第一行(标题)与正文(第二行)没有相同的空间。

希望有人能帮助我了解这有什么问题

结果是这样的

我想要的是

在此输入图像描述

我的代码是:

<TableLayout
        android:layout_width="match_parent"
        android:layout_height="0dp">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1" >

            <TextView
                android:layout_height="match_parent"
                android:layout_weight="0.6" />

            <ImageView
                android:layout_height="wrap_content"
                android:layout_weight="0.1"/>

            <ImageView
                android:layout_height="wrap_content"
                android:layout_weight="0.1" />

            <ImageView
                android:layout_height="wrap_content"
                android:layout_weight="0.1"" />

            <ImageView
                android:layout_height="match_parent"
                android:layout_weight="0.1" />
        </TableRow>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
              >

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="1" >

                    <TextView
                        android:layout_height="0dp"
                        android:layout_weight="0.6" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />
                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="1" >

                    <RelativeLayout
                        android:layout_height="wrap_content"
                        android:layout_weight="0.6" >        

                        <TextView
                       android:layout_width="wrap_content"
                        android:layout_height="wrap_content" 
                       />

                    </RelativeLayout> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml

1
推荐指数
1
解决办法
2912
查看次数

我想把图像放在按钮上

我想将 png 图像放在按钮上,我尝试过 android:background 但 png 占据了所有按钮,我想要的正是像这样在按钮上使用徽标 png

在此处输入图片说明

信息徽标是我的 png,“关于”来自按钮文本

eclipse android android-layout android-xml android-button

1
推荐指数
1
解决办法
4824
查看次数

Android NaviagtionDrawer Item 文本对齐

我像这样创建了 NavigationView 我的导航视图截图

,这是我的 xml 代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/top_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Dashbored">

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

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tool_bar"
android:elevation="7dp"
android:fitsSystemWindows="true"
tools:openDrawer="end">


<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include layout="@layout/f_home_screen" />

</FrameLayout>


</LinearLayout>

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#0284fe"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:itemBackground="@drawable/drawer_backg"
app:itemIconTint="@color/drawer_item"
app:itemTextAppearance="@style/NavDrawerTextStyle"
app:itemTextColor="@color/windowBackground"
app:menu="@menu/main_drawer" />


</android.support.v4.widget.DrawerLayout>
</RelativeLayout>   
Run Code Online (Sandbox Code Playgroud)

我想像这样设置项目文本对齐中心

我需要这样的输出

这是我的菜单 xml

<?xml version="1.0" encoding="utf-8"?><menu 
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_inspec_rpt"
android:title="INSPECTION REPORTS"
/>
<item
android:id="@+id/nav_action"
android:title="ACTION ITEMS"
/>
<item
android:id="@+id/nav_appoint"
android:title="APPOINTMENTS" />
<item …
Run Code Online (Sandbox Code Playgroud)

android android-xml android-studio navigation-drawer

1
推荐指数
1
解决办法
4731
查看次数

1
推荐指数
1
解决办法
3732
查看次数

移除 AppBarLayout 周围的边框

我有一个看起来像这样的片段:

截屏

在屏幕底部(底部导航栏的正上方)彼此相邻的粉红色圆点和灰色圆点的正上方,有一条水平灰线。

无论如何我可以删除它吗?

该片段具有以下布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".home.tutorial.TutorialFragment">



<android.support.v4.view.ViewPager
    android:id="@+id/tutorialViewPager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/appBar"
    android:background="@android:color/white"/>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    app:layout_constraintTop_toBottomOf="@id/tutorialViewPager"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">

    <me.relex.circleindicator.CircleIndicator
        android:id="@+id/circleIndicator"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        app:ci_drawable="@drawable/tab_indicator_selected"
        app:ci_drawable_unselected="@drawable/tab_indicator_default"
        app:ci_height="6dp"
        app:ci_width="6dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"/>


</android.support.design.widget.AppBarLayout>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我看了这篇文章:删除操作栏边框

但考虑到我不想从操作栏中删除边框,我认为它不适用。

android android-xml android-appbarlayout

1
推荐指数
1
解决办法
2222
查看次数

如何从主题更改 CardView 背景颜色

在具有多个主题的应用程序中,如何从样式文件更改 CardView 的背景颜色?

样式文件

<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimaryTheme1</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDarkTheme1</item>
        <item name="colorAccent">@color/colorAccentTheme1</item>
</style>

<style name="AppTheme2" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimaryTheme2</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDarkTheme2</item>
        <item name="colorAccent">@color/colorAccentTheme2</item>
</style>

<style name="AppTheme3" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimaryTheme3</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDarkTheme3</item>
        <item name="colorAccent">@color/colorAccentTheme3</item>
</style>

Run Code Online (Sandbox Code Playgroud)

卡片视图

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    android:elevation="4dp"
    app:cardCornerRadius="15dp">
Run Code Online (Sandbox Code Playgroud)

我想更改每个主题的背景颜色,我希望在styles.xml 文件中完成此操作。

android android-xml android-styles android-cardview

1
推荐指数
1
解决办法
1965
查看次数

Android - 底部导航菜单所选项目的图标颜色由于碎片而没有改变

底部导航所选项目的颜色没有改变,尽管我提供了控制颜色变化的可绘制文件。我已经尝试了很多次,但我找不到代码中的错误。

请帮忙!

这是底部导航

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="@color/bottomBackground"
        app:itemTextColor="@drawable/icon_color"
        app:itemIconTint="@drawable/icon_color"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/bottom_navigation_menu"/>
Run Code Online (Sandbox Code Playgroud)

这是 icon_color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/colorAccent" android:state_checked="true"/>
    <item android:color="@color/grey" android:state_checked="false"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

编辑 :

当我删除这段代码时它工作正常

        BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            int id = menuItem.getItemId();
            if(id == R.id.navigation_library) {
                loadFragment(new LibraryFragment());
            }
            else if (id == R.id.navigation_for_you) {
                loadFragment(new ForYouFragment());
            }
            return false;
        }
    });
Run Code Online (Sandbox Code Playgroud)

为什么这段代码会干扰我的功能。

android android-layout android-xml bottomnavigationview material-components

1
推荐指数
1
解决办法
4586
查看次数

底部导航不显示原始颜色

我为我的应用程序设计了底部导航视图。这个想法很简单,绿色底部栏将有白色图标。我为此写了一个选择器

<?xml version="1.0" encoding="utf-8"?>
  <selector xmlns:android="http://schemas.android.com/apk/res/android">

     <item android:state_checked="false" android:color="@android:color/white" />
     <item android:color="@android:color/holo_blue_dark"  />
  </selector>
Run Code Online (Sandbox Code Playgroud)

它有效,它改变了图标颜色,但它并没有使其完全变成白色,颜色看起来呈灰色。我也尝试过,<item android:state_selected="true" android:color="@android:color/white" />但它也不起作用。我添加了下面的图片供您查看差异。

图像

请帮忙

android android-xml android-bottomnav android-bottomnavigationview

1
推荐指数
1
解决办法
2331
查看次数

自定义底部导航栏项目布局

我想创建以下自定义底部导航栏。如何为菜单项设置自定义布局?或者是否存在可以轻松创建这种类型的底部栏的现成库?

在此处输入图片说明

java android android-xml android-design-library

1
推荐指数
1
解决办法
2271
查看次数

Android - 如何将ArrayList的值设置为TextView

我有一个问题.我从我的解析器类的结果中得到了ArrayList.那么我想把这个值(ArrayList中的值)放到TextView上.

这是我迄今为止所做的工作.我在main.xml上创建TextView

<TextView
        android:id="@+id/deskripsi" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
    />
Run Code Online (Sandbox Code Playgroud)

在我的onCreate方法中,我初始化了文本视图

desk = (TextView)findViewById(R.id.deskripsi);
Run Code Online (Sandbox Code Playgroud)

然后我试图从谷歌地图和节点地标解析KML文件我把它的值放到ArrayList,这里我的代码

ArrayList<String> pathName = new ArrayList<String>();
Object[] objPlace;

//Parser Node Placemark
NodeList nlPlace = doc.getElementsByTagName("Placemark");
        for(int p = 0; p < nlPlace.getLength(); p++){
            Node rootPlace = nlPlace.item(p);
            NodeList itemPlace = rootPlace.getChildNodes();
            for(int y = 0; y < itemPlace.getLength(); y++){
                Node placeStringNode = itemPlace.item(y);
                NodeList place = placeStringNode.getChildNodes();
                //valueName = nameList.item(0).getNodeValue().toString() + "+";
                pathName.add(place.item(0).getNodeValue());
            }
    }

objPlace = pathName.toArray();

desk.setText("");
for (int j = 0; j < objPlace.length; j++){ …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml

0
推荐指数
1
解决办法
2万
查看次数