xml 相关问题

可扩展标记语言(XML)是一种灵活的结构化文档格式,用于定义人类和机器可读的编码规则。

需要什么 XSLT 来提取和转换这个特定的 XHTML?

我正在尝试从较大的文件中提取一些 HTML 的子集,然后对结果执行一些转换。我已经取得了一些进展,但我缺少一两部分来使这项工作成为设计......

回答 1 投票 0

使用已知元素查找父元素的属性

不确定标题是否清楚,但基本上我有一些如下所示的XML: 测试1 不确定标题是否清楚,但基本上我有一些如下所示的 XML: <details> <result id=1234567890> <name>Test1</name> </result> <result id=5345345433> <name>Test2</name> </result> <result id=9572385354> <name>Test3</name> </result> 我想要完成的是找到使用已知值的 id 属性 即测试1 > 1234567890,测试2 > 5345345433,测试3 > 9572385354 最好使用 xmllint,但 xmlstarlet 也是一个选项。 输入 首先,您的 XML 无效。你的id属性需要被qouted,并且详细信息没有关闭。这是修改后的输入: <details> <result id="1234567890"> <name>Test1</name> </result> <result id="5345345433"> <name>Test2</name> </result> <result id="9572385354"> <name>Test3</name> </result> </details> 结果 下面将使用 xmlstarlet 提取给定 name 属性的特定 id。 xmlstarlet sel -t -c "/details/result[name='Test1']" test.xml | grep -Po "(?<=id=\")[\d]*" 这会回来 1234567890 您也可以将命令中的 Test1 替换为变量。 var=Test1 xmlstarlet sel -t -c "/details/result[name='$var']" test.xml | grep -Po "(?<=id=\")[\d]*" 故障 xmlstarlet sel -t -c "/details/result[name='$var']" test.xml 选择结果中与 $var 匹配的所有名称标签。 | grep -Po "(?<=id=\")[\d]*" 使用 Perl Regex 将输出通过管道传输到 grep 以查找 id 属性并打印所有包含的数字。 您还可以使用xmllint: xmllint --xpath "string(/details/result[name='Test1']/@id)" yourfile.xml --xpath:告诉 xmllint 使用 xpath 语法进行选择。 xpath选择器的详细信息: string(/details/result[name='Test1']/@id) string():制作字符串 /details/result:选择result元素的details子元素 [name='Test1']:包含一个name节点,其值为Test1 /@id:id属性值(result元素) 也许一个简单的 grep 和 awk 解决方案适合您。 grep -B1 Test1 sample.xml | awk '/id=/{gsub(/[^0-9]+/, "", $0); print $0 }' 完整回答OP的问题, #/bin/bash # # how to use xmllint to get information from specific elements # REQUIRES libxml2 (sorry Snow Leopard!) mytestxml=' <details> <result id="1234567890"> <name>Test1</name> </result> <result id="5345345433"> <name>Test2</name> </result> <result id="9572385354"> <name>Test3</name> </result> </details> ' echo Test Document is :"$mytestxml" echo Get the contents of the \''id'\' attribute of a specific \''result'\' element query=\''string(/details/result[3]/@id)'\' echo xpath query is "$query" myresult=$(echo "$mytestxml" | xmllint --xpath 'string(/details/result[3]/@id)' - ) echo info returned is "$myresult" echo "" echo Get the specific \''result'\' node whose \''name'\' element is \"Test1\" query=\''/details/result[name="Test1"]'\' echo xpath query is "$query" myresult=$(echo "$mytestxml" | xmllint --xpath '/details/result[name="Test1"]' - ) echo info returned is "$myresult" echo "" echo Get the \''id'\' attribute of the specific \''result'\' node whose \''name'\' element is \"Test1\" query=\''string(/details/result[name="Test1"]/@id)'\' echo combined xpath query is "$query" myresult=$(echo "$mytestxml" | xmllint --xpath 'string(/details/result[name="Test1"]/@id)' - ) echo info returned is "$myresult" 获取特定“result”元素的“id”属性的内容。 xpath 查询是: 'string(/details/result[3]/@id)' 返回的信息是:9572385354 获取'name'元素为“Test1”的特定'result'节点 xpath 查询是: '/details/result[name="Test1"]' 返回的信息是: <result id="1234567890"> <name>Test1</name> </result> 获取'name'元素为“Test1”的特定'result'节点的'id'属性 组合的 xpath 查询是: 'string(/details/result[name="Test1"]/@id)' 返回的信息是1234567890 希望这对找到此页面的其他人有用。 :o) 这样的东西应该与 xmlstarlet 一起使用(对我有用): xmlstarlet sel --template --match "/details/result[name='Test1']" --value-of "@id" test.xml

回答 5 投票 0

使用 JSXB 将 xml 通用映射到 java bean

我已将 xml 内容映射到 java bean。我正在使用 JAXB 将其转换为我的 bean 类。 这很好用。但为此我需要事先知道xml的内容。如果添加一些新元素...

回答 1 投票 0

TextInput 在小屏幕手机上显示太窄

在以下 xml 中,“message_entry”在小屏幕 (240 x 320) 上显示太窄,但在较大屏幕 (480 x 640) 上显示良好。 在以下 xml 中,“message_entry”在小屏幕 (240 x 320) 上显示太窄,但在较大屏幕 (480 x 640) 上显示良好。 <androidx.cardview.widget.CardView android:id="@+id/reply_bar_card" android:layout_width="match_parent" android:layout_height="wrap_content" app:cardBackgroundColor="@color/replyBarCard" app:cardCornerRadius="24dp" app:cardElevation="5dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="24dp"> <ProgressBar android:id="@+id/send_progress" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="3dp" android:indeterminate="true" android:visibility="invisible" /> <HorizontalScrollView android:id="@+id/attached_image_scroller" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/message_list_padding" android:layout_marginEnd="@dimen/message_list_padding" android:paddingTop="8dp" android:paddingBottom="8dp" android:scrollbars="none" android:visibility="gone"> <LinearLayout android:id="@+id/attached_image_holder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="12dp" android:layout_marginEnd="12dp" android:orientation="horizontal" /> </HorizontalScrollView> <LinearLayout android:id="@+id/smart_reply_container" android:layout_width="match_parent" android:layout_height="56dp" android:layout_marginStart="@dimen/message_list_padding" android:layout_marginEnd="@dimen/message_list_padding" android:gravity="end" android:orientation="horizontal" android:visibility="gone"> <ImageButton android:id="@+id/close_smart_replies" android:layout_width="32dp" android:layout_height="48dp" android:layout_gravity="center_vertical" android:layout_marginStart="8dp" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/use_smart_replies" android:src="@drawable/ic_cancel" android:tint="@color/secondaryText" /> <LinearLayout android:id="@+id/smart_reply_suggestions_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginEnd="12dp" android:layout_weight="1" android:gravity="end" android:orientation="horizontal" /> </LinearLayout> <LinearLayout android:id="@+id/send_bar" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginStart="@dimen/message_list_padding" android:layout_marginEnd="@dimen/message_list_padding" android:alpha="0" android:clipToPadding="false" android:gravity="center_vertical|start" android:orientation="horizontal" android:padding="8dp" android:translationY="-32dp"> <ImageButton android:id="@+id/select_sim" android:layout_width="32dp" android:layout_height="48dp" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/select_sim" android:src="@drawable/ic_sim" android:tint="@color/secondaryText" android:visibility="gone" /> <ImageButton android:id="@+id/view_scheduled_messages" android:layout_width="32dp" android:layout_height="match_parent" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/view_scheduled_messages" android:src="@drawable/ic_schedule_small" android:tint="@color/secondaryText" android:visibility="gone" /> <FrameLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginEnd="8dp"> <ImageButton android:id="@+id/attach" android:layout_width="32dp" android:layout_height="48dp" android:layout_gravity="center_vertical|start" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/attach" android:src="@drawable/ic_attach" android:tint="@color/secondaryText" /> <TextView android:id="@+id/text_counter" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:layout_marginBottom="2dp" android:gravity="center_horizontal" android:textColor="@color/secondaryText" android:textSize="12sp" /> </FrameLayout> <com.google.android.material.textfield.TextInputEditText android:id="@+id/message_entry" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@null" android:backgroundTint="@color/drawerBackground" android:hint="@string/type_message_to" android:imeOptions="actionSend|flagNoExtractUi" android:inputType="textCapSentences|textAutoCorrect|textMultiLine" android:maxLines="@integer/message_list_fragment_line_entry_count" android:minHeight="40dp" android:padding="8dp" android:paddingStart="8dp" android:paddingEnd="18dp" android:scrollHorizontally="false" android:textSize="16sp" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:contentDescription="@string/send_message" android:src="@drawable/ic_send" app:elevation="0dp" app:fabSize="mini" app:rippleColor="@android:color/white" /> </LinearLayout> <ViewStub android:id="@+id/attach_stub" android:layout_width="match_parent" android:layout_height="@dimen/attach_menu_height" android:layout="@layout/view_attach_menu" /> </LinearLayout> </androidx.cardview.widget.CardView> 小屏幕:(添加红框用于说明) 大屏幕:(添加红框作为说明) 预期的行为就像大屏幕,其中“message_entry”尽可能宽。为什么“message_entry”在小屏幕上那么窄?我该如何解决它? 原来是因为dimens.xml文件夹下有多个res文件造成的。这用于支持多种屏幕尺寸,在较小屏幕的 dimens.xml 中,有 <dimen name="message_list_padding">96dp</dimen>。一旦更改为0dp,布局就如预期的那样。 有关多个 dimens.xml 文件的更多信息,请参阅此答案中的#2。

回答 1 投票 0

rtf 模板中的除法公式问题 - XML Publisher

我有一个单元格(假设单元格 A)中的“bucket_3”列和另一个单元格(假设单元格 B)中的“EXPOSURE”列的总和。 我正在尝试使用以下代码计算 A 除以 B 即 A/B: 我有一个单元格(假设单元格 A)中的“bucket_3”列和另一个单元格(假设单元格 B)中的“EXPOSURE”列的总和。 我正在尝试使用以下代码计算 A 除以 B 即 A/B: <?if:sum(EXPOSURE)=0 ?> <?xdoxslt:div(sum(BUCKET_3),sum(EXPOSURE))?> <?else?> <?end if?> this gives no result. 当我尝试时 <?xdoxslt:div(sum(BUCKET_3),sum(EXPOSURE))?> 结果为 0。 请帮忙。预先感谢。 请尝试以下 xdofx 功能。这应该有效- <?xdofx: sum(BUCKET_3) div sum(EXPOSURE)?> https://docs.oracle.com/cd/E21764_01/bi.1111/e13881/T527073T558233.htm

回答 1 投票 0

如何将图像放在按钮上android studio

我有一个512x512px的齿轮png图像(用于设置),我希望它放在一个按钮上。 我试图在可绘制的目录中创建一个目录以保持事物井井有条,但这不起作用,所以我把...

回答 1 投票 0

使用冒泡排序算法进行向量排序

我是编程新手,目前正在开发一个应用程序来帮助管理我的家庭预算。所有数据都存储在 XML 文件中。为了按日期对向量进行排序,我实现了冒泡排序算法......

回答 1 投票 0

如何在 Odoo 17 中的动作锯齿内添加按钮

我在第一个红框中有一个按钮,我想把它放在锯轮图标中,我该如何编写js来做到这一点? 我在模型 hr.employee 的树视图中。

回答 1 投票 0

我无法从 mujoco py 修改 xml 文件

我想制作我的自定义mujocogym环境,但是由于它很难,我删除了hopper.xml的xml脚本并用我编写的代码替换。所以如果我这样做 ''' env =gym.make(“Hopper-v4”) 环境仁...

回答 3 投票 0

尝试向发票门户视图 Odoo 16 添加按钮

我一直在尝试添加一个按钮来向 Odoo 中发票的门户视图添加签名,我怀疑问题出在我正在使用的外部 ID 上(或者可能是版权问题?),但我已经尝试过

回答 1 投票 0

使用 Java 和带有 CodeArtifact 依赖项的 Maven 构建 Dockerfile

我正在尝试使用 Docker 构建我的项目,它有一些 Java REST API,我在多服务架构上使用 Maven 和 Spring Boot。我有一个名为“common-utilit...

回答 1 投票 0

perl XML::LibXML 何时需要 new() 调用

我用perl的XML::LibXML写了一个程序 它使用 load_xml() 创建 XML::LibXML。 我很惊讶它不需要调用 new()。 什么时候需要调用new()? 这是代码

回答 1 投票 0

如何使用 Go 和 etree XML 包访问同级元素?

给定一个如下所示的 XML 文档: 今天 1 给定一个如下所示的 XML 文档: <MasterXML> <Processes> <Params> <ParamName>today</ParamName> <ParamType>1</ParamType> <ParamValue/> </Params> <Params> <ParamName>today</ParamName> <ParamType>2</ParamType> <ParamValue/> </Params> <Params> <ParamName>today</ParamName> <ParamType>3</ParamType> <ParamValue/> </Params> </Processes> </MasterXML> 使用 beevik/etree for Go 包,当 <ParamValue/> 具有特定的特定值时,如何访问文档中 <Params> 的每个实例的 <ParamName>,以用值填充它。 在给定的示例中,当 <ParamValue/> 持有值 today 时,我希望用 05/02/2024 填充所有 <Params> 节点中的所有 <ParamName> 节点。 此代码仅适用于包含许多实例的文档中 <Params> 节点的第一个实例,其中 <ParamName>== today ,尽管循环似乎应该访问 <Params> 的每个实例: for _, elem1 := range doc.FindElements(".//Processes//Params//ParamName") { if elem1 == nil { log.Fatal("Check XPath) } s := elem1.Text() if s == "today" { elem2 := elem1.FindElement("//ParamValue") elem2.SetText("05/02/2024") } } 我该怎么做?为什么 range doc.FindElements(".//Processes//Params//ParamName") 找不到 <Params> 的每个实例?我应该使用不同的方法吗? 您当前的代码确实按照您所描述的方式运行,因为通过在 XPath 中使用双斜杠,您始终以递归方式搜索 XML 树,这意味着您始终从顶部找到第一个出现的位置。 这是固定样本: package main import ( "log" "os" "strings" "github.com/beevik/etree" ) func main() { doc := etree.NewDocument() if err := doc.ReadFromFile("master.xml"); err != nil { panic(err) } for _, elem1 := range doc.FindElements(".//Processes//Params//ParamName") { if elem1 == nil { log.Fatal("Check XPath") } s := elem1.Text() //println(s) if strings.TrimSpace(s) == "today" { elem2 := elem1.FindElement("../ParamValue") elem2.SetText("05/02/2024") } } doc.WriteTo(os.Stdout) } 这需要 master.xml 与您的 .go 文件位于同一目录中。我选择了这个: <MasterXML> <Processes> <Params> <ParamName> today </ParamName> <ParamType>1</ParamType> <ParamValue/> </Params> <Params> <ParamName> tomorrow </ParamName> <ParamType>2</ParamType> <ParamValue/> </Params> <Params> <ParamName> today </ParamName> <ParamType>3</ParamType> <ParamValue/> </Params> </Processes> </MasterXML> 产生所需的输出: <MasterXML> <Processes> <Params> <ParamName> today </ParamName> <ParamType>1</ParamType> <ParamValue>05/02/2024</ParamValue> </Params> <Params> <ParamName> tomorrow </ParamName> <ParamType>2</ParamType> <ParamValue/> </Params> <Params> <ParamName> today </ParamName> <ParamType>3</ParamType> <ParamValue>05/02/2024</ParamValue> </Params> </Processes> </MasterXML>

回答 1 投票 0

转义字符串以在 XML 中使用

我正在使用 Python 的 xml.dom.minidom 创建 XML 文档。 (逻辑结构 -> XML 字符串,而不是相反。) 我如何让它转义我提供的字符串,这样他们就无法找到我......

回答 8 投票 0

在 SQL 中查询 XML 以返回 NULL 和空数据集的节点结果列表

我有一个包含一个 XML 列的 SQL 表,我想查询 XML 并获取 id/@extension 以及所有观察/代码的列表。但是它总是返回空结果。我已经隔离了一个考试...

回答 1 投票 0

Android 项目构建

引起:org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException:无法解析配置“:app:debugRuntimeClasspath”的所有文件。 我想要bui...

回答 1 投票 0

如何使用 PHP 读取带有 HTML 标签的 XML?

我已经多次使用 php 和 XML,但这种 XML 在开头和结尾都有 Html 标签: 链接到 XML 没有到 xml 文件的直接链接,所以我必须使用

回答 2 投票 0

在 xml 响应中链接到 php 变量[重复]

我从连接脚本中链接得到这个结果, [email protected] http://m3.licdn.com/mpr/mprx/

回答 3 投票 0

如何将 R 中的分层节点数据转换为数据框?

我有以下 xml 文件。 我有以下 xml 文件。 <?xml version="1.0" encoding="UTF-8"?> <gudid xmlns="http://www.fda.gov/cdrh/gudid" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://www.fda.gov/cdrh/gudid gudid.xsd"> <header> <database frequency="monthly" id="5460" type="FULL"> <downloadFile part="1" totalParts="174"/> <numberRecordXML>25000</numberRecordXML> <numberRecordsDatabase>4334252</numberRecordsDatabase> </database> <creationDate>2024-04-01T03:30:00</creationDate> <period end="2024-04-01T03:30:00" start="2014-09-24T00:00:00"/> </header> <device xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.fda.gov/cdrh/gudid"> <publicDeviceRecordKey>33db3dc9-1c5e-4670-a3e1-b52ae0e8c7f0</publicDeviceRecordKey> <publicVersionStatus>Update</publicVersionStatus> <deviceRecordStatus>Published</deviceRecordStatus> <!--Note: publicVersionNumber is system generated and assigned to all device records to track public release updates to a device record--> <publicVersionNumber>3</publicVersionNumber> <publicVersionDate>2018-07-06</publicVersionDate> <devicePublishDate>2016-09-01</devicePublishDate> <deviceCommDistributionEndDate xsi:nil="true"></deviceCommDistributionEndDate> <deviceCommDistributionStatus>In Commercial Distribution</deviceCommDistributionStatus> <identifiers> <identifier> <deviceId>M991NM82330A243</deviceId> <deviceIdType>Package</deviceIdType> <deviceIdIssuingAgency>HIBCC</deviceIdIssuingAgency> <containsDINumber>M991NM82330A242</containsDINumber> <pkgQuantity>4</pkgQuantity> <pkgDiscontinueDate xsi:nil="true"></pkgDiscontinueDate> <pkgStatus>In Commercial Distribution</pkgStatus> <pkgType>Case</pkgType> </identifier> <identifier> <deviceId>M991NM82330A242</deviceId> <deviceIdType>Package</deviceIdType> <deviceIdIssuingAgency>HIBCC</deviceIdIssuingAgency> <containsDINumber>M991NM82330A241</containsDINumber> <pkgQuantity>8</pkgQuantity> <pkgDiscontinueDate xsi:nil="true"></pkgDiscontinueDate> <pkgStatus>In Commercial Distribution</pkgStatus> <pkgType>Box</pkgType> </identifier> <identifier> <deviceId>M991NM82330A241</deviceId> <deviceIdType>Primary</deviceIdType> <deviceIdIssuingAgency>HIBCC</deviceIdIssuingAgency> <containsDINumber xsi:nil="true"></containsDINumber> <pkgQuantity xsi:nil="true"></pkgQuantity> <pkgDiscontinueDate xsi:nil="true"></pkgDiscontinueDate> <pkgStatus xsi:nil="true"></pkgStatus> <pkgType xsi:nil="true"></pkgType> </identifier> </identifiers> <brandName>Clear-View MAX &quot;Sub-Q&quot; Infusion Set</brandName> <versionModelNumber>ClearView™MAX</versionModelNumber> <catalogNumber>NM82330A-24</catalogNumber> <dunsNumber>013861471</dunsNumber> <companyName>NORFOLK MEDICAL</companyName> <deviceCount>1</deviceCount> <deviceDescription>24G x 12mm x 24&quot; Clear-View MAX &quot;Sub-Q&quot; Infusion Set</deviceDescription> <DMExempt>true</DMExempt> <premarketExempt>false</premarketExempt> <deviceHCTP>false</deviceHCTP> <deviceKit>false</deviceKit> <deviceCombinationProduct>false</deviceCombinationProduct> <singleUse>true</singleUse> <lotBatch>true</lotBatch> <serialNumber>false</serialNumber> <manufacturingDate>true</manufacturingDate> <expirationDate>true</expirationDate> <donationIdNumber>false</donationIdNumber> <labeledContainsNRL>false</labeledContainsNRL> <labeledNoNRL>true</labeledNoNRL> <MRISafetyStatus>Labeling does not contain MRI Safety Information</MRISafetyStatus> <rx>true</rx> <otc>false</otc> <contacts> <customerContact> <phone>+1(847)674-7075</phone> <phoneExtension>102</phoneExtension> <email>[email protected]</email> </customerContact> </contacts> <premarketSubmissions> <premarketSubmission> <submissionNumber>K870188</submissionNumber> <supplementNumber>000</supplementNumber> </premarketSubmission> </premarketSubmissions> <gmdnTerms> <gmdn> <gmdnCode>35833</gmdnCode> <gmdnPTName>Electric infusion pump administration set, single-use</gmdnPTName> <gmdnPTDefinition>A collection of sterile devices (e.g., plastic tubing, check valve, roller clamp, Y-site connector, Luer, needle/catheter) intended to be used in combination with an electrically-powered infusion pump for the intravenous (IV), subcutaneous, intramuscular, or epidural administration of medication. This is a single-use device.</gmdnPTDefinition> <implantable>false</implantable> <gmdnCodeStatus>Active</gmdnCodeStatus> </gmdn> </gmdnTerms> <productCodes> <fdaProductCode> <productCode>FPA</productCode> <productCodeName>Set, administration, intravascular</productCodeName> </fdaProductCode> </productCodes> <deviceSizes> <deviceSize> <sizeType>Needle Gauge</sizeType> <size value="24" unit="Gauge"/> <sizeText xsi:nil="true"></sizeText> </deviceSize> </deviceSizes> <environmentalConditions/> <sterilization> <deviceSterile>true</deviceSterile> <sterilizationPriorToUse>true</sterilizationPriorToUse> <methodTypes> <sterilizationMethod>Ethylene Oxide</sterilizationMethod> </methodTypes> </sterilization> </device> </gudid> 我想将其转换为数据框。标识符具有层次结构并且存在三个标识符。我编写的代码如下,但在这种情况下,所有标识符都放在标识符列的一个单元格中,导致无法区分这些值。 setwd('D:/') doc <- read_xml('xmltest.xml') xml <- xmlParse(doc) df <- xmlToDataFrame(xml) 此外,我只想将设备节点转换为数据帧,而头节点保持不变。 这里是一个使用 jsonlite 库将列表转换为数据框的 around 方法。 library(xml2) library(jsonlite) page <- read_xml('xmltest.xml' ) #strip the names spaces xml_ns_strip(page) #convert to a list and then use json lite library to covert into a data frame xml_find_all(page, ".//identifier") %>% as_list() %>% jsonlite::toJSON() %>% jsonlite::fromJSON(simplifyDataFrame = TRUE)

回答 1 投票 0

ViewPager下如何设置TabLayout?

我在LinearLayout中有TabLayout和ViewPager2: 我在 LinearLayout 中有 TabLayout 和 ViewPager2: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/main_tabLayout"/> <androidx.viewpager2.widget.ViewPager2 android:layout_width="match_parent" android:layout_height="0dp" android:id="@+id/view_pager" android:layout_weight="1"/> </LinearLayout> 它工作正常,但我需要 ViewPager 下的 TabLayout。如果我交换它们,TabLayout 不会显示(ViewPager 可见并且工作正常)。 ViewPager下如何设置TabLayout? 我试过了 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.viewpager2.widget.ViewPager2 android:layout_width="match_parent" android:layout_height="0dp" android:id="@+id/view_pager" android:layout_weight="1"/> <com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/main_tabLayout"/> </LinearLayout> 在这种情况下,只有 ViewPager 可见 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.viewpager2.widget.ViewPager2 android:layout_width="match_parent" android:layout_height="0dp" android:id="@+id/view_pager" android:layout_weight="1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/main_tabLayout" /> <com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/main_tabLayout" android:visibility="visible" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 尝试使用这个布局。希望它会起作用。

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.